Luc, it is the script you collaborated with the OP to get working.
##########################################################
#
# Mark Jones 2/20/2012
# Version 2
#
##########################################################
#Prompt for domain username/password and local admin password
$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 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.pdns
$sdns = $item.sdns
$vlan = $item.vlan
$pass = $item.pass
$adminpass = $item.adminpass
$username = $item.username
#Clone the templates
New-VM -Name $vmname -template $template -Datastore $datastore -VMHost $vmhost -RunAsync
}
while (get-task -status running | Where-Object {$_.name -eq "clonevm_task"})
{
sleep 20
}
foreach ($item in $vmlist) {
$datastore = $item.datastore
$vmhost = $item.vmhost
$custspec = $item.custspec
$ipaddr = $item.ipaddress
$subnet = $item.subnet
$gateway = $item.gateway
$pdns = $item.pdns
$sdns = $item.sdns
$vlan = $item.vlan
$vmname = $item.vmname
$username = $item.username
$pass = $item.pass
$adminpass = $item.adminpass
#set customization spec
New-OSCustomizationSpec -spec $custspec -Name $vmname -type Persistent
Set-OSCustomizationSpec -spec $vmname -AdminPassword $adminpass -DomainUsername $username -DomainPassword $pass -Confirm:$false
Get-OSCustomizationSpec $vmname | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIp -IpAddress $ipaddr -SubnetMask $subnet -DefaultGateway $gateway -Dns $pdns,$sdns
#Set network label
Get-VM -Name $vmname | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $vlan -Confirm:$false | Out-Null
#set vm
#Set-VM -VM $vmname -OSCustomizationSpec $vmname -NumCpu $cpu -MemoryMB $mem -Confirm:$false
#Remove Cust Spec
Remove-OSCustomizationSpec -CustomizationSpec $vmname -Confirm:$false
#Start VM
Start-VM -VM $vmname -Confirm:$false
}