如何通过powershell将计算机加入域

如何通过powershell将计算机加入域,powershell,Powershell,我刚刚重新安装了windows 7 professional,我想通过powershell将我的pc加入到域中,但这里出现了一些错误,这是我正在使用的代码 Add-Computer -ComputerName HMD-PC002 -DomainName mydomain -Credential mydomain\Administrator Add-Computer : Computer 'HMD-PC002' failed to join domain 'mydomain' from

我刚刚重新安装了windows 7 professional,我想通过powershell将我的pc加入到域中,但这里出现了一些错误,这是我正在使用的代码

Add-Computer -ComputerName HMD-PC002 -DomainName mydomain -Credential     
mydomain\Administrator

Add-Computer : Computer 'HMD-PC002' failed to join domain 'mydomain' from its current  
workgroup 'WORKGROUP' with
following error message: Unknown error (0xa8b).
At C:\Users\HMDPC002\Desktop\add-pc_to_Domain.ps1:8 char:1
+ Add-Computer -ComputerName HMD-PC002 -DomainName mydomain -Credential mydomain\A ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : OperationStopped: (HMD-PC002:String) [Add-Computer],   
InvalidOperationException
+ FullyQualifiedErrorId :   
FailToJoinDomainFromWorkgroup,Microsoft.PowerShell.Commands.AddComputerComma

根据您的说明,它已经在运行,并且根据错误代码,在进行搜索时,它似乎与AD有关,请参考下面的链接,尝试查看它是否按照建议通过IP工作。

有一个简单的解决方案,我没有配置我的dns服务器,我必须手动更改它,在填充两个字段后,我运行以下脚本,它工作了

Add-Computer -DomainName mydomain -Credential mydomain\Administrator -Restart

但是,我希望powershell更改dns设置,我将在一个单独的问题中询问此问题,在将服务器加入域之前我做了什么:

1) 检查DC和服务器之间的连接。Ping域控制器。若两者都在同一子网上,则应ping,否则无法加入域

2) 运行此powershell命令:

PS C:\Windows\system32>添加计算机域.com-凭据域\管理员 警告:重新启动计算机SERVERNAME后,更改将生效