Trying to join a VMware guest VM to my domain. I'm running the Powershell script from one of my other guest vm's in VMware vCenter. I've tried changing the $Domain variable to other string names like "MATLOCKHOME" "MATLOCKHOME.COM" but still getting the error "DNS name contains an invalid character."
I can ping the dns hostname and ip from the guest vm that I'm running the script from.
Function Join-Domain ($VM, $HC, $GC, $OUPath, $Domain, $DomainUser, $DomainPassword) {
$joind = "c:\windows\system32\netdom.exe join /d:$Domain $VM /OU:$OUPath /userd:$DomainUser /passwordd:$DomainPassword"
Invoke-VMScript -VM $VM -HostCredential $HC -GuestCredential $GC -ScriptType bat -ScriptText $joind
}
Connect-VIServer -Server "vcsa01.matlockhome.com" -User [email protected] -Password <REDACTED>
$VM = Get-VM ( Read-Host "Enter VM name" )
$ESXHost = $VM | Get-VMHost
$HostCred = $Host.UI.PromptForCredential("Please enter credentials", "Enter ESX host credentials for $ESXHost", "root", "")
$GuestCred = $Host.UI.PromptForCredential("Please enter credentials", "Enter Guest credentials for $VM", "", "")
$DomainUser = "MATLOCKHOME\Administrator"
$DomainPassword = "<REDACTED>"
$Domain = "MATLOCKHOME.com"
$OUPath = "OU=Computers,DC=matlockhome,DC=com"
Join-Domain $VM $HostCred $GuestCred $Domain $OUPath $DomainUser $DomainPassword