尝试将 VMware 客户虚拟机加入我的域。我正在 VMware vCenter 中从我的其他客户虚拟机之一运行 Powershell 脚本。我尝试将 $Domain 变量更改为其他字符串名称,如“MATLOCKHOME”“MATLOCKHOME.COM”,但仍然收到错误“DNS 名称包含无效字符”。
我可以从运行脚本的客户虚拟机 ping dns 主机名和 ip。
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