【问题标题】:Change a user password on remote domain in PowerShell在 PowerShell 中更改远程域上的用户密码
【发布时间】:2019-08-29 09:37:57
【问题描述】:

我需要能够允许来自远程域的用户更改他们的密码,并且我无法安装 RSAT 工具和他们将使用的机器。

我尝试使用Invoke-Command 传递域管理员凭据在域控制器上运行一些代码,但是我无法让Invoke-Command 进行身份验证。

$InvUsername = "admin"
$InvPassword_Text = "adminpassword"
$InvPassword = ConvertTo-SecureString -AsPlainText $InvPassword_Text -Force
$InvCreds = New-Object System.Management.Automation.PSCredential -ArgumentList $InvUsername,$InvPassword

$InvSession = New-PSSession -ComputerName 'DC01.domain.co.uk' -Credential $InvCreds 

New-PSSession -ComputerName 'DC01.domain.co.uk' -Credential $InvCreds
New-PSSession : [DC01.domain.co.uk] Connecting to remote server DC01.domain.co.uk failed with the following error message : The user name or password is incorrect.

顺便说一句,密码不是错误的。

【问题讨论】:

  • 尝试将该域限定符添加到用户名?作为测试,尝试 $InvCreds = Get-Credential 并在提示时手动输入凭据作为 DOMAIN\username 和密码
  • 我得到同样的错误
  • PSSession 很可能无法跨不受信任的域工作。事实上,这表明不是:“简而言之,默认的 Kerberos 身份验证只能在域或信任边界内工作。您需要启用并指定另一种身份验证机制。安全的方法是仅使用 HTTPS,然后使用基本身份验证。不要将 Basic 与 HTTP 结合使用,因为它会以明文形式显示凭据。"
  • 这篇文章似乎相关:serverfault.com/questions/624762/…
  • 谢谢,我现在正在阅读这篇文章。

标签: windows powershell active-directory


【解决方案1】:

您需要创建一个新的远程 PowerShell 会话来执行此操作吗?您可以直接联系其中一位域控制器吗?

您可以尝试使用 .NET 的 DirectoryEntry 并传递凭据。如果你知道账号的distinguishedName

$user = New-Object System.DirectoryServices.DirectoryEntry("LDAP://CN=user,DC=example,DC=com", $username, $password)
$user.Invoke("SetPassword","NewPassword123")

您可能还必须告诉它通过 LDAPS(LDAP over SSL)端口显式连接,如下所示:

$user = New-Object System.DirectoryServices.DirectoryEntry("LDAP://DC01.domain.co.uk:636/CN=user,DC=example,DC=com", $username, $password)

但这也假设 LDAPS 使用您的计算机信任的证书正确设置。

【讨论】:

  • Set-ADAccountPassword 是 RSAT 的一部分,很遗憾我无法在机器上安装它,
  • 我添加了另一种方式,您无需安装任何东西就可以做到这一点。
  • 这看起来很有希望。我会在早上测试它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-14
相关资源
最近更新 更多