VMware Cloud Community
Amadeus1756
Contributor
Contributor
Jump to solution

PowerCLI - customizations on Redhat5, hostname not set correctly

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.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
Amadeus1756
Contributor
Contributor
Jump to solution

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 -NamingSchemeFixed” –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.

0 Kudos