簡體   English   中英

在PowerShell中更改遠程域上的用戶密碼

[英]Change a user password on remote domain in PowerShell

我需要能夠允許來自遠程域的用戶更改密碼,並且我無法安裝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.

密碼不是正確的順便說一句。

您需要創建一個新的遠程PowerShell會話嗎? 您可以直接聯系其中一個域控制器嗎?

您可以嘗試使用.NET的DirectoryEntry並傳遞憑據。 如果您知道帳戶的distinguishedName名稱:

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

您可能還必須告訴它通過LDAPS(基於SSL的LDAP)端口進行顯式連接,如下所示:

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

但這還假定已使用計算機信任的證書正確設置了LDAPS。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM