0

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

enter image description here

3
  • What happens when you run the netdom command interactively (no script)?
    – Greg Askew
    Jun 19, 2023 at 10:14
  • @GregAskew I was incorrectly passing the parameters in the Join-Domain function call. So Powershell was passing the $OUPath where the $Domain parameter was supposed to be. The correct order of parameters are: Join-Domain $VM $HostCred $GuestCred $OUPath $Domain $DomainUser $DomainPassword Jun 19, 2023 at 16:59
  • Classic example here of the reason why you should use named parameters: powershell-guru.com/… rather than relying on the position of the parameters passed only. Also check out learn.microsoft.com/en-us/powershell/module/… Jul 6, 2023 at 3:56

0

You must log in to answer this question.