Change AD password for user on a different domain with PowerShell

  • 11 months ago
Comment

ChatGPT
1 / 1

You can change the Active Directory password for a user on a different domain using PowerShell by establishing a remote connection to the domain where the user account resides. Here's a general outline of how you can achieve this:

  1. Import the Active Directory module (if not already imported):

    powershell
    Import-Module ActiveDirectory
  2. Establish a remote PowerShell session to the target domain using the Enter-PSSession cmdlet:

    powershell
    $remoteSession = New-PSSession -ComputerName <RemoteDomainController> -Credential <RemoteCredentials>
    Enter-PSSession -Session $remoteSession

    Replace <RemoteDomainController> with the hostname or IP address of the remote domain controller, and <RemoteCredentials> with appropriate credentials for accessing the remote domain.

  3. Change the password for the user using the Set-ADAccountPassword cmdlet:

    powershell
    Set-ADAccountPassword -Identity <Username> -OldPassword <OldPassword> -NewPassword <NewPassword> -Reset -PassThru

    Replace <Username> with the username of the user whose password you want to change, <OldPassword> with the user's current password, and <NewPassword> with the new password you want to set.

  4. Exit the remote PowerShell session:

    powershell
    Exit-PSSession

Here's the complete script:

powershell
Import-Module ActiveDirectory

$remoteSession = New-PSSession -ComputerName <RemoteDomainController> -Credential <RemoteCredentials>
Enter-PSSession -Session $remoteSession

Set-ADAccountPassword -Identity <Username> -OldPassword <OldPassword> -NewPassword <NewPassword> -Reset -PassThru

Exit-PSSession

Replace the placeholders <RemoteDomainController>, <RemoteCredentials>, <Username>, <OldPassword>, and <NewPassword> with the appropriate values.

Please note that using remote PowerShell sessions requires proper network connectivity, permissions, and authentication to the remote domain. Additionally, be aware of security considerations when managing credentials and remote connections.