Hi,
I'm trying to join a new server build to the domain via Invoke-VMScript. I'm hoping to script the whole server build process, or a good majority of it, to save on mouse clicks.
The script starts off by connecting to our vCenter server, so it can then reach the remote server and run the script below. Everything works, except for the add-computer line. When it gets to that piece it just hangs. Even without the sleep 10 line.
If i modify this, remove the invoke-vmscript command and I run the Add-Computer command on the VM locally, it joins the domain and reboots just fine. Any idea what I'm doing wrong, and how i can have the server join the domain and reboot via Invoke-VMScript?
My test server for this script is a brand new build and VMTools are up to date.
$scriptCode="
## Configure the IP address and gateway ##
New-NetIpAddress -InterfaceAlias Ethernet0 -IPAddress $ip -PrefixLength 24 -DefaultGateway $gway
## Configure the DNS Server IP address ##
Set-DnsClientServerAddress -InterfaceAlias Ethernet0 -ServerAddresses $dns
## wait for 10 seconds ##
sleep 10
## add the server to the domain and reboot ##
Add-Computer –domainname $domain -restart -credential $cred2
"
#use the invoke-vmscript command to send all of the code in the $scriptCode variable above to the remote server
Invoke-VMScript-VM$vm-ScriptText$scriptCode-GuestCredential$cred