使用 PowerShell 更改不同域中用户的 AD 密码 [英] Change AD password for user on a different domain with PowerShell

查看:109
本文介绍了使用 PowerShell 更改不同域中用户的 AD 密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改位于不同域的用户的密码,而不是我在其中执行操作的主机.这是我拥有的示例代码:

I'm trying to change the password for user that is on a different domain than the host where I'm doing it from. This is the example code that I have:

$domain = 'someADDomain.local'
$userName = 'SomeUser'

$oldPassword = Read-Host -AsSecureString -Prompt "Enter the account's old password"
$newPassword = Read-Host -AsSecureString -Prompt "Enter a new password"

Set-ADAccountPassword -Server $domain -Identity $userName -OldPassword $oldPassword -NewPassword $newPassword

问题是我收到服务器拒绝了客户端凭据".需要修改密码的用户只能登录特定的服务器,不能登录域控制器.

The issue is that I'm getting "The server rejected the client credentials". The user that needs password changed is only allowed to login to specific servers, not the domain controller.

除了域名之外,有没有办法指定使用哪个服务器?

Is there a way to specify which server to use, in addition to the domain name?

参考:https://social.technet.microsoft.com/Forums/en-US/bae9fa8f-f602-4533-97fe-9b2bc9bb800d/powershell-how-to-reset-domain-account-password-for-multiple-domains?forum=ITCG

推荐答案

当前域中的当前用户显然没有权限更改其他域中用户的密码,这意味着您需要提供其他凭据(请参阅-Credential) 到 Set-ADAccountPassword cmdlet.

The current user in the current domain has apparently no permission change the password of the user in the other domain, meaning that you will need to provide other credentials (see -Credential) to the Set-ADAccountPassword cmdlet.

试试:

$Password = ConvertTo-SecureString "PlainTextPassword" -AsPlainText -Force $oldPassword
$Credential = New-Object System.Management.Automation.PSCredential ("$domain\$userName", $Password)
Set-ADAccountPassword -Credential $Credential -Server $domain -Identity $userName -OldPassword $oldPassword -NewPassword $newPassword
#                     -----------------------

在示例中,我假设用户有权更改(自己的)密码,否则您将需要提供其他凭据,例如其他域的域管理员凭据.这可能只是OtherDomain\YourAccountName)

In the example I presume that the user has permission to change (its own) password, otherwise you will need to supply other credential, e.g. domain administrator credentials of the other domain. This could just be OtherDomain\YourAccountName)

这篇关于使用 PowerShell 更改不同域中用户的 AD 密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆