We are trying to automate creation of VMs based on a spread sheet (csv file). These VMs will be based on the template. Template is specified in the sheet. The script works fine and machines are created. However, computer does not join domain. IP and computer name are successfully changed.
Need help in figuring out how to troubleshoot this issue. Following is the snippet used for setting the IP and domain.
New-OSCustomizationSpec -OrgName "Company" -OSType Windows `
-Description $vm.Description -Domain "mydomain" -DomainUsername "domainuser" -DomainPassword "password" `
-ChangeSid -AdminPassword "newpassword" -Name wincli -Type "Persistent" -FullName "Windows Custom Spec"
Get-OSCustomizationNicMapping -OSCustomizationSpec wincli | Set-OSCustomizationNicMapping -Position 1 -IpMode UseStaticIP -IpAddress $vmIP -SubnetMask $vmSubNet -DefaultGateway $vmGateway -Dns $vmDNS1,$vmDNS2 -Confirm:$false
New-OSCustomizationNicMapping –OSCustomizationSpec wincli -Position 2 -IpMode UseStaticIP -IpAddress $vmIP -SubnetMask $vmSubNet -DefaultGateway $vmGateway -Dns $vmDNS1,$vmDNS2 -Confirm:$false
$custom = Get-OSCustomizationSpec -name wincli
$NewVM = New-VM -ResourcePool $resourcePool -Name $vmname -Location $folder -Datastore $datastore -Template $template -OSCustomizationSpec $custom -confirm:$true
Comment from BenH was right on target.
It worked after adding using the format of username as pointed by BenH. (Username: user@domain.xyz.com, domain: domain.xyz.com)