Hi,
I'm new to using PowerCLI so I may be being dumb, so do say if I'm making a stupid mistake.
I want to create a number of machines based on a template; the only thing that will differ is the hostname and the IP address.
I have a CSV file:
VM,Datastore,VMhost,IP
nwb-vb85sp1rh5x64c1t1,vmfs-vb-s08,nwb-devesx01.microfocus.com,10.120.70.167
And I am processing this with the following script.
Import-Csv "
nwb-vb85sp1rh5x64.csv" | %{
Get-OSCustomizationSpec
VBautomation_VLAN70 | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIp -IpAddress $_.
IP -SubnetMask 255.255.255.0
–DefaultGateway 10.120.70.254
New-VM -VMhost $_.VMhost -name $_.VM -Template
nwb-vb85sp1rh5x64Level3 -Datastore $_.Datastore -OSCustomizationSpec
“VBautomation_VLAN70”
}
Once the machine has been booted, the hostname is not nwb-vb85sp1rh5c1t1 but nwb-vb85sp1rh5c1t1-0 (the template, if booted would have a hostname of nwb-vb85sp1rh5templ, so something is happening). Is this a known issue? Does anyone have any idea as to how I can get the right machine name? I have a load of scripts which do various things based on a hostname and changing all these would be be a pain.
Many thanks.
I suspect the NamingScheme in your OSCustomizationSpec might be wrong.
You can change that with the Set-OSCustomizationSpec cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I suspect the NamingScheme in your OSCustomizationSpec might be wrong.
You can change that with the Set-OSCustomizationSpec cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc - that did indeed fix it. For reference, by script is now:
Import-Csv "
nwb-vb85sp1rh5x64.csv" | %{
Get-OSCustomizationSpec
VBautomation_VLAN70 | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIp -IpAddress $_.
IP -SubnetMask 255.255.255.0
–DefaultGateway 10.120.70.254
Get-OSCustomizationSpec
VBautomation_VLAN70 |
Set-OSCustomizationSpec -
NamingScheme “Fixed” –NamingPrefix$_.VM
New-VM -VMhost $_.VMhost -name $_.VM -Template
nwb-vb85sp1rh5x64Level3 -Datastore $_.Datastore -OSCustomizationSpec
“VBautomation_VLAN70”
}
Quite why the default of "Vm" didn't work (I also tried it explicitly) I don't know - I expected it to. No matter, I'm working now.
Thanks very much.