Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
263 views
in Technique[技术] by (71.8m points)

powershell - PowerCLI Scripted deployment of static IP VMs - erroring

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...