Ah, we have same thing lots of VLAN's but we just set the network label before powering on so it is on the proper vlan while it customizes and then joins the domain. It does it all on the fly So, when your VM's boot they are on a DHCP Vlan and then you change the ip later?
EDIT: the set OS customization spec will modify the vlan information in the cust spec. Here is how I do it just for reference if you are interested. Basically doing the same thing, just different methods
$vcenter=Read-Host"Enter Vcenter Name"
$csvimport=Read-Host"Enter CSV filename (fullname with extension)"
$username=read-host"Enter your domain admin username for customization"
$pass=Read-Host-AsSecureString"Enter your password"
$adminpass=Read-Host-AsSecureString"Enter local admin password"
#convert back to string
$pass= [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pass)
$pass= [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($pass)
$adminpass= [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($adminpass)
$adminpass= [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($adminpass)
Connect-VIServer$vcenter
$vmlist=Import-CSV$csvimport
#Define Tasks Array
$tasks= @()
foreach ($itemin$vmlist) {
$basevm=$item.template
$datastore=$item.datastore
$cluster=$item.cluster
$custspec=$item.custspec
$vmname=$item.vmname
$ipaddr=$item.ipaddress
$subnet=$item.subnet
$gateway=$item.gateway
$pdns=$item.pdns
$sdns=$item.sdns
$vlan=$item.vlan
$hd= [int]$item.ddrive *1024*1024
$vmname=$item.vmname
$cpu=$item.cpu
$mem= [int]$item.mem *1024
$vds=$item.vsm
#set customization spec
New-OSCustomizationSpec-OSCustomizationSpec$custspec-Name$vmname-typeNonPersistent | Out-Null
Set-OSCustomizationSpec-OSCustomizationSpec$vmname-AdminPassword$adminpass-DomainUsername$username-DomainPassword$pass-Confirm:$false | Out-Null
Get-OSCustomizationSpec$vmname | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping-IpModeUseStaticIp-IpAddress$ipaddr-SubnetMask$subnet-DefaultGateway$gateway-Dns$pdns,$sdns | Out-Null
$OsCustomization=Get-OSCustomizationSpec$vmname
#Clone the templates and add to tasks list. It will spin all up at the same time
$tasks+= (New-VM-Name$vmname-OSCustomizationSpec$OScustomization-template$basevm-Datastore$datastore-ResourcePool$cluster-RunAsync)
}
Write-Host"Waiting for Copies to Finish"
#Wait for all taksks in tasks list before proceeding
Wait-Task-task$tasks
#Set network Label and add harddrives by looping through list and doing one at a time
foreach ($itemin$vmlist) {
$vmname=$item.vmname
$vlan=$item.vlan
$hd= [int]$item.ddrive *1024*1024
$cpu=$item.cpu
$mem= [int]$item.mem *1024
$vds=$item.vsm
#Set network label
$vdportgroup=Get-VDPortgroup-Name$vlan-VDSwitch$vds
Get-VM-Name$vmname | Get-NetworkAdapter-Name"Network adapter 1" | Set-NetworkAdapter-Portgroup$vdportgroup-Confirm:$false
#set vm
Set-VM-VM$vmname-NumCpu$cpu-MemoryMB$mem-Confirm:$false
#Create D drive windows
if ($hd){
New-HardDisk-VM$vmname-CapacityKB$hd-StorageFormatThin-Confirm:$false
}
}
#Loop through list and power all VM's on simultaneously
foreach ($itemin$vmlist){
$vmname=$item.vmname
#Start VM
Start-VM-VM$vmname-Confirm:$false-RunAsync
}
Disconnect-VIServer$vcenter-confirm:$false