通过Powershell将远程机器添加到AD

所以我有一个PowerShell脚本, Add-Computer -ComputerName $computername -LocalCredential $computername\admin -DomainName $domain -Credential domain\$username -Force -Restart

所以,如果我有一台机器已经脱离了或被禁用,并且运行以下命令,我得到一个错误: Remove-Computer : Cannot establish the WMI connection to the computer '$computername' with the following error message: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA). Remove-Computer : Cannot establish the WMI connection to the computer '$computername' with the following error message: The RPC server is unavailable. (Exception from HRESULT: 0x800706BA).

现在我已经证实,这台机器实际上是在networking上,我能够RDP到它。 是否有什么错误,或者如果机器在AD中不活动,这将不起作用?

如果我在本地计算机上set-item wsman:\localhost\Client\TrustedHosts -value * ,就可以find它来允许来自不受信任的源的远程连接,因为证书错误不会popup。

然后将其移动到它运行的ScriptBlock

添加计算机将本地计算机添加到域: 链接

您可以尝试使用PowerShell Remoting添加您的机器

假设您的机器在线,请确保远程registry服务正在运行并可访问,即。 禁用防火墙或创build一个例外。