The following script doesn't seem to be setting a static IP from the csv file. Any ideas as to what I should check?
# Define the naming convention for the virtual machines.
$vmNameTemplate = "Test123-{0:D3}"
# Save the cluster in which the virtual machines should be created into a variable.
$cluster = Get-Cluster test-cluster
# Save the template on which the virtual machines should be based into a variable.
$template = Get-Template test123
# Save the static IP addresses from the stored CSV file into a variable.
$staticIpList = Import-CSV C:\StaticIPs.csv
# Create the vitrual machines.
$vmList = @()
for ($i = 1; $i –le 2; $i++) {
$vmName = $vmNameTemplate –f $i
$vmList += New-VM –Name $vmName –ResourcePool $cluster –Template $template
}
# Create the customization specification.
$linuxSpec = New-OSCustomizationSpec –Name test-custom –Domain test.com –DnsServer "192.168.10.1" –NamingScheme VM –OSType Linux
# Clone the customization specification to a nonpersistent type.
$specClone = New-OSCustomizationSpec –Spec $linuxSpec –Type NonPersistent
# Apply the customization specification to each virtual machine.
for ($i = 0; $i –lt $vmList.Count; $i++) {
# Acquire a new static IP from the list
$ip = $staticIpList[$i].IP
# The specification has a default NIC mapping – retrieve it and update it with the static IP
$nicMapping = Get-OSCustomizationNicMapping –OSCustomizationSpec $specClone
$nicMapping | Set-OSCustomizationNicMapping –IpMode UseStaticIP –IpAddress $ip –SubnetMask "255.255.255.0" –DefaultGateway "192.168.10.1"
# Apply the customization
Set-VM –VM $vmList[$i] –OSCustomizationSpec $specClone –Confirm:$false
}
Write-Host ""
Disconnect-VIServer -Confirm:$false
What exactly do you have in that CSV file?
A single column with the name IP?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes....
IP
192.168.xxx.xxx
192.168.xxx.xxx
All in different cells of course....
It's not clear from you script, but do you actually power on the VM, and is the OSCustomization running at that point?
Did you check the OSCustomization logs, as documented in KB1026317
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You do realise that the OS customisation runs at the 1st power on?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The logs I mentioned earlier should contain clues why it didn't do anything.
If there are no logs something fundamentally went wrong. In that case have a look at the vmware.log of the VM.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference