Thanks, I agree on the prompt. But I am new to deploying VMs in this manner so I wasn't sure how it was supposed to work. However, this is the script I am using:
Connect-VIServer vcenter.domain.com
$vmlist = Import-CSV C:\vms.csv
foreach ($item in $vmlist) {
# I like to map out my variables
$Template = $item.template
$datastore = $item.datastore
$vmhost = $item.vmhost
$custspec = $item.custspec
$vmname = $item.vmname
$ipaddr = $item.ipaddress
$subnet = $item.subnet
$gateway = $item.gateway
$pdns = $item.pdnswins
$sdns = $item.sdnswins
#Get the Specification and set the Nic Mapping (Apply 2 DNS/WINS if 2 are present)
If ($Varable) {
Get-OSCustomizationSpec $custspec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIp -IpAddress $ipaddr -SubnetMask $subnet -DefaultGateway $gateway -Dns $pdns,$sdns
} else {
Get-OSCustomizationSpec $custspec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIp -IpAddress $ipaddr -SubnetMask $subnet -DefaultGateway $gateway -Dns $pdns
}
#Clone the BaseVM with the adjusted Customization Specification
New-VM -Name $vmname -Template $Template -Datastore $datastore -VMHost $vmhost | Set-VM -OSCustomizationSpec $custspec -RunAsync -Confirm:$false
#Remove the NicMapping (Don't like to leave things unkept)
Get-OSCustomizationSpec $custspec | Get-OSCustomizationNicMapping | Remove-OSCustomizationNicMapping -Confirm:$false
and the .cvs looks like this:
Template,datastore,vmhost,custspec,vmname,ipaddress,subnet,gateway,pdnswins,sdnswins
Template_w2k3r2e64,vm02a_storage,vm02a.domain.com,w2k3r2e64qa,w2k3r2e64-vm,10.102.30.128,255.255.255.0,10.102.30.1,10.0.2.35,10.0.2.60
Which isn't working, if I comment out the last line it will work. However if I don't it will create the VM but it will hang with the message below:
cmdlet Remove-OSCustomizationNicMapping at command pipeline position 3
Supply values for the following parameters:
OSCustomizationNicMapping[0]:
If I comment out that line it creates the VMS without fail but obvously never sets the static IP. Any ideas?