【问题标题】:Access is Denied when Reset-ComputerMachinePassword is run through Invoke-command通过 Invoke-command 运行 Reset-ComputerMachinePassword 时拒绝访问
【发布时间】:2015-01-22 21:26:43
【问题描述】:

我正在使用以下命令重置远程机器' 密码。

$user="Domain\domainadmin";
$pass="dapassword" | ConvertTo-SecureString -AsPlainText -Force;
$creds=New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $pass;
Invoke-Command -Credential $creds -ComputerName "DomainControllerMachine" -ScriptBlock{ 
$ComputerName = @"
SomeRemoteHost
"@
Import-Module ActiveDirectory; 
Reset-ComputerMachinePassword -Server ${ComputerName};
}

我不断收到“访问被拒绝”错误。

This command cannot be executed on target computer('DomainControllerMachine') due to following error: Access is
 denied.
    + CategoryInfo          : InvalidOperation: (DomainControllerMachine:String) [Reset-ComputerMachinePasswor
   d], InvalidOperationException
    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.ResetCompute
   rMachinePasswordCommand

我使用的帐户对 ActiveDirectory 具有所有级别的访问权限。因此,用于身份验证的凭据不会有问题。

如果我在“DomainControllerMachine”上运行相同的命令(以同一用户身份登录),它工作正常。

Import-Module ActiveDirectory; 
Reset-ComputerMachinePassword -Server "SomeRemoteHost";

即使上面的整个调用命令块也可以正常工作,而不会在 DomainControllerMachine 上抱怨。 但是当我通过 Invoke-Command 或 Enter-PSSession 远程执行此操作时,我会收到可怕的拒绝访问错误..

在机器上设置 WSManCredSSP(客户端、委托和服务器)后,我也尝试使用 CredSSP,但没有成功。

我可能遗漏了什么,或者有没有更好的方法来处理这种情况?

【问题讨论】:

  • 您是在重置帐户的同一台机器上执行此操作吗?
  • 您是否尝试过将调用的命令作为脚本存储在目标机器上,然后使用调用来运行该脚本? social.technet.microsoft.com/Forums/en-US/…
  • 在提升的提示符下运行你的powershell会话(右键单击-> 以管理员身份运行
  • @mjolinor 不,它们是不同的机器
  • @Raf 是的,我总是这样做。 shell 以管理员身份运行。

标签: powershell powershell-remoting invoke-command


【解决方案1】:

在我看来,您正在域控制器上运行 Reset-computermachinepassword 命令。据我所知,它应该在需要在 -server 字段中使用 DC 名称重置的计算机上运行。

为此,您需要在需要重置凭据的计算机上运行命令:

Reset-Computermachinepassword -server "DomainControllerMachine" -credential $PScredential

如果计算机启用了 powershell 远程处理,您可以尝试使用 PSsession 远程执行此操作。您将需要指定不同的身份验证方法来访问已失去对域的信任的计算机。

您可以使用 Credssp,但这仅在您的 GPO 允许将您的凭据委派给目标计算机时才有效。 或者您可以使用基本身份验证。但要使其正常工作,Target 必须接受未加密的流量。

远程执行的命令可能如下所示:

$session = new-PSSession "targetcomputer" -Authentication Basic -Credential  "Domain\domainadmin"
Invoke-Command -Session $session -scriptblock {Reset-Computermachinepassword -server "Domain\domainadmin"}

【讨论】:

  • 关闭。我得到Cannot validate argument on parameter 'Session'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again。我还用-server "myserver.domain.com" 替换了你的-server "Domain\domainadmin",但这就是我所做的一切。但这是一个很好的答案,因为它解释了您无法在 DC 上运行该命令并期望它在不执行 hocus-pocus 的情况下更新受影响的服务器。
猜你喜欢
  • 2018-03-10
  • 1970-01-01
  • 2015-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-22
  • 1970-01-01
相关资源
最近更新 更多