Score:0

VMware Guest VM Join My Own Domain With Netdom Fails ""DNS name contains an invalid character"

is flag

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

cn flag
What happens when you run the netdom command interactively (no script)?
Mark Matlock avatar
is flag
@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
Pimp Juice IT avatar
ch flag
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
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.