- 1 year ago
Change AD password for user on a different domain with PowerShell
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:
Import the Active Directory module (if not already imported):
powershellImport-Module ActiveDirectory
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.Change the password for the user using the
Set-ADAccountPassword
cmdlet:powershellSet-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.Exit the remote PowerShell session:
powershellExit-PSSession
Here's the complete script:
powershellImport-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.