【发布时间】:2014-05-07 17:56:19
【问题描述】:
我正在我们的测试环境中进行一些自动化,我们有 powershell 脚本来将 Windows 客户端加入域或工作组。
如果域中不存在客户端的计算机帐户,我在尝试将 Windows 7 客户端从域移动到工作组时遇到问题。
代码如下:
$User = administrator
$Password = ConvertTo-SecureString "<password>" -AsPlainText -Force
$DomainCred = New-Object System.Management.Automation.PSCredential $User, $Password
remove-computer -credential $DomainCred -force -passthru -verbose
这是返回的错误:
VERBOSE: Performing operation "Remove-Computer" on Target "localhost".
Remove-Computer: This command cannot be executed on target computer ('xxx')
due to following error: No mapping between account names and security IDs was done.
At line :1 char:16
+ remove-computer <<<< -credential $DomainCred -force -passthru -verbose
+ CategoryInfo : InvalidOperation: (xxx:String) [Remove-Computer],
InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.Powershell.
Commands.RemoveComputerCommand
但是,如果我使用 GUI(计算机属性、高级系统设置、计算机名称、更改...)尝试此操作,它会提示输入凭据并成功。
如何将此操作复制到 powershell 命令中,以便实用地完成?
【问题讨论】:
标签: windows powershell dns active-directory powershell-2.0