That's got it. Just in case anyone else is trying to do the same thing here's the final code:
$esxName = "prodh1.MYDOMAIN.local"
$template = "W2K8R2SP1"
$datastore = "IOMEGA"
$newVmList = @(
@{"Name" = "SRV01"; "IP" = "192.168.1.100"; "Netmask" = "255.255.255.0"; "Gateway" = "192.168.1.1"; "DNS" = @("192.168.1.2", "192.168.1.3"); "NetworkName" = "VM2"; },
@{"Name" = "SRV02"; "IP" = "192.168.1.101"; "Netmask" = "255.255.255.0"; "Gateway" = "192.168.1.1"; "DNS" = @("192.168.1.2", "192.168.1.3"); "NetworkName" = "VM2"; },
@{"Name" = "SRV03"; "IP" = "192.168.1.102"; "Netmask" = "255.255.255.0"; "Gateway" = "192.168.1.1"; "DNS" = @("192.168.1.2", "192.168.1.3"); "NetworkName" = "VM2"; },
@{"Name" = "SRV04"; "IP" = "192.168.1.103"; "Netmask" = "255.255.255.0"; "Gateway" = "192.168.1.1"; "DNS" = @("192.168.1.2", "192.168.1.3"); "NetworkName" = "VM2"; }
)
$custSpec = "W2K8R2SP1"
$location = "_Tobedeleted"
$taskTab = @{}
Connect-VIServer -Server VIRTUALCENTERSERVER.MYDOMAIN.local -User MYDOMAIN\MYUSER -Password MYPASSWORD
# Create all the VMs specified in $newVmList
foreach($VM in $newVmList) {
$taskTab[(New-VM -Name $VM.Name -VMHost (Get-VMHost -Name $esxName) -Template $template -Datastore $datastore -OSCustomizationSpec $custSpec -Location $location -RunAsync).Id]=$VM.Name
}
# Start each VM that is completed
$runningTasks = $taskTab.Count
while($runningTasks -gt 0){
Get-Task | % {
if($taskTab.ContainsKey($_.Id) -and $_.State -eq "Success"){
Get-VM $taskTab[$_.Id] | Start-VM
$taskTab.Remove($_.Id)
$runningTasks--
}
elseif($taskTab.ContainsKey($_.Id) -and $_.State -eq "Error"){
$taskTab.Remove($_.Id)
$runningTasks--
}
}
Start-Sleep -Seconds 15
}
# START HERE
# Wait for OS Customization
Start-Sleep -Seconds 1020
# Customize network
foreach($VM in $newVmList) {
Get-NetworkAdapter -VM $VM.Name | Set-NetworkAdapter -NetworkName $VM.NetworkName -Confirm:$false
Get-VM -Name $VM.Name | Get-VMGuestNetworkInterface -Guestuser "Administrator" -GuestPassword "MYPASSWORD" | ? { $_.name -eq "Local Area Connection 3" } | Set-VMGuestNetworkInterface -Guestuser "Administrator" -GuestPassword "MYPASSWORD" -IPPolicy static -IP $VM.IP -Netmask $VM.Netmask -Gateway $VM.Gateway -DNS $VM.DNS
}
One change I had to make was to crank the sleep time way up in order to allow the OS Customization to run.
Thanks so much for all your help Emanuel!!