首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Powershell重新加入域的脚本

问使用Powershell重新加入域的脚本
EN

Stack Overflow用户
提问于 2011-11-29 03:58:22
回答 2查看 8.8K关注 0票数 0

对不起,我的英语不好。

我在运行Windows7的VMWare ESXi上有虚拟机。所有计算机都在域中,但有时它们会离开域,因此我需要重新加入域。我写了一个简单的脚本来做这件事:

代码语言:javascript
复制
$credential = New-Object System.Management.Automation.PsCredential("mydomain\user", (ConvertTo-SecureString "password" -AsPlainText -Force))
Add-Computer -WorkGroupName TEMP -Credential $credential
Add-Computer -DomainName "mydomain" -Credential $credential
Restart-Computer

但是它不工作;我有这个错误:

代码语言:javascript
复制
Add-Computer : This command cannot be executed on target computer('') due to following error: An existing connection was forcibly closed by the remote host.
At C:\Tools\Re-Join.ps1:2 char:13
+ Add-Computer <<<<  -WorkGroupName TEMP -Credential $credential
+ CategoryInfo          : InvalidOperation: (:) [Add-Computer], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.AddComputerCommand<br>

如果我手动加入'workgroup‘,然后运行脚本,一切正常。

EN

回答 2

Stack Overflow用户

发布于 2011-11-30 21:28:13

下面是我用来加入域的脚本:

代码语言:javascript
复制
$computer = Get-WmiObject Win32_ComputerSystem
$computer.JoinDomainOrWorkGroup("cloud.com" , "PASSWORD HERE", "USER", $null, 3)
Restart-Computer -Force
票数 1
EN

Stack Overflow用户

发布于 2013-06-04 00:37:56

您可以在加入之前添加一个退出,重新加入域名之前不需要重新启动:

代码语言:javascript
复制
$computer.UnJoinDomainOrWorkGroup("PASSWORD HERE", "USER", 0)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8301554

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档