VMware Cloud Community
pkrampek
Contributor
Contributor

Set_static_IPs_for cloned_VMs_ does_not_run

Hi All,

There is created a sript what  does the following:

1st: makes a clone VMs about the source Linux one - It is OK, no any error durint the script, clone VMs are done.

2nd: Import the IPs from the StaticsIPs.csv- It is OK, no any error during the script

3rd: create a Linux customization specification- It is OK, no any error during the script. Linux customization specification is created in the vCenter

4th: make a non persistent clone about the Linux customization specification - It is OK, no any error during the script

5th: assign the static IP to the cloned VM. It doesn't run properly.There is an error message, screen attached about it.

Could you please help me?

It is the scipt:

$vCenter="vcenter01.lab.sitea"

$vCenterUser="administrator@vsphere.local"

$vCenterUserPassword="jels0.9%"

$clone = "TestLinux"

$vmNameTemplate = “TestLinux-{0:D3}”

$vm_count = "1"

$clone = "TestLinux"

$ds = "Lab_Low"

$Folder = "LabFolder"

$Cluster = "LabCluster"

Connect-viserver $vCenter -user $vCenterUser -password $vCenterUserPassword -WarningAction 0

$vmList = @()

for ($i = 1; $i –le 2; $i++) {

$vmName = $vmNameTemplate –f $i

$ESXi=Get-Cluster $Cluster | Get-VMHost -state connected | Get-Random

write-host "Creation of VM $VM_name initiated" -foreground green

$vmList += New-VM -Name $VmName -VM $clone -VMHost $ESXi -Datastore $ds -Location $Folder

}

$staticIpList = Import-CSV C:\StaticIPs.csv

$linuxSpec = New-OSCustomizationSpec –Name LinuxCustomization –Domain labmhm.hu –NamingScheme Prefix -NamingPrefix "TestLinux" –OSType Linux –DnsServer 192.168.1.1

$specClone = New-OSCustomizationSpec –Spec $linuxSpec –Type NonPersistent

for ($i = 0; $i -lt $vmList.Count; $i++)

{

$ip = $staticIpList[$i].IP

$nicMapping = Get-OSCustomizationNicMapping –OSCustomizationSpec $specClone

$nicMapping | Set-OSCustomizationNicMapping –IpMode UseStaticIp –IpAddress $ip –SubnetMask 255.255.255.0 DefaultGateway 192.168.1.254

Set-VM –VM $vmList[$i] –OSCustomizationSpec $specClone

}

Error message is also attached during step 5th in the script

Yours assistant and coooperation is highly appreciated in this matter!

Sincerely,

Peter

0 Kudos
4 Replies
LucD
Leadership
Leadership

Which PowerCLI version are you using?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
LucD
Leadership
Leadership

It looks like you might have forgotten the column header, IP, in the CSV file.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
pkrampek
Contributor
Contributor

HiLucD,

I attached wrong screen about the .csv file in my previous post here.

It is the correct(btw: the result the same)

pastedImage_2.png

PowerCLI Version:

pastedImage_0.png

pastedImage_3.png

Thank you in advance!

0 Kudos
LucD
Leadership
Leadership

Are you sure about that column header, because in the script you use the property IP, not IPAddress?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos