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 administrator@vsphere.local -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

Mark Matlock
  • 13
  • 1
  • 5
  • What happens when you run the netdom command interactively (no script)? – Greg Askew Jun 19 '23 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 – Mark Matlock Jun 19 '23 at 16:59
  • Classic example here of the reason why you should use named parameters: https://powershell-guru.com/powershell-best-practice-2-use-named-parameters-not-positional-and-partial-parameters/ rather than relying on the position of the parameters passed only. Also check out https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_parameters?view=powershell-7.3#parameter-position – Pimp Juice IT Jul 06 '23 at 03:56

0 Answers0