PowerCLI Scripted deployment of static IP VMs - erroring

1.3k views Asked by At

Thought what I was trying to do was simple. I have my own /25 subnet and Vmware cluster and I want to deploy a bunch of Windows 2012r2 VMs from a good template. My hosts will be basically host10 through host50 and the IP address will be 10.251.169.10-50...the last octet matching the number in the host name. So I decided to do a powershell loop. I'm running into a problem I can't figure out.

$gateway = 10.251.169.1
$pdns = 1.1.1.1
$sdns = 2.2.2.2
$pwins - 3.3.3.3
$subnetmask = 255.255.255.128
$Networkname = "vm_network"

foreach($i in 10..12){

#Setting VM name and IP based on position in the loop
$vmname = "azww-qc-$($i)d"
$ipaddress = "10.251.169.$i"


#Setting up $custspec variable
$custSpec = New-OSCustomizationSpec -Type NonPersistent -OSType Windows `
-OrgName “MyOrg” -FullName “Name” -Domain “mydomain.com” `
–DomainUsername “user” –DomainPassword “password”

#Adding network information to custspec
$custSpec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP `
-IpAddress $ipaddress -SubnetMask $subnetmask -Dns $pdns -wins $pwins -DefaultGateway $gateway

 New-VM -Name $vmname -Template $template -datastore $cluster `
-NumCPU 2 -MemoryGB  4 -DiskGB 35 -NetworkName $networkname `
-OSCustomizationSpec $custSpec

}

I keep getting the following error:
Set-OSCustomizationNicMapping When the IpMode parameter is set to UseStaticIp, you must specify the IPAddress, Subnetmask, Dns(on Windows specs only), and DefaultGateway parameters.

I am specifying those parameters, so I don't know what it's barking about.

1

There are 1 answers

0
noam On

Try enclosing the IPs in quotes. You also seem to have typo-ed the equals sign with $pwins. So:

$gateway = "10.251.169.1"
$pdns = "1.1.1.1"
$sdns = "2.2.2.2"
$pwins = "3.3.3.3"
$subnetmask = "255.255.255.128"

Offhand I'm not sure why $x = 1.1.1.1 sets $x to $null, but that's what happens.