PowerCLI Scripted deployment of static IP VMs - erroring

人走茶凉 提交于 2019-12-14 03:25:14

问题


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:


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.



来源:https://stackoverflow.com/questions/27008147/powercli-scripted-deployment-of-static-ip-vms-erroring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!