Last active
July 13, 2019 17:13
-
-
Save mattvanstone/4f40ebcc903b5396cfa01fcc70237889 to your computer and use it in GitHub Desktop.
Change the password of multiple Active Directory accounts across multiple domains at once
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Change the password of multiple Active Directory accounts across multiple domains at once. | |
# Assumes that all of the passwords were the same to begin with. | |
Write-Host "=====================" | |
Write-Host "Password Reset Script" | |
Write-Host "=====================" | |
$oldPass = Read-Host -AsSecureString -Prompt "Old password" | |
$newPass = Read-Host -AsSecureString -Prompt "New password" | |
$accounts = @( | |
[pscustomobject]@{username='username1';domain='myfirstdomain.com';server='mydc.myfirstdomain.com'} | |
[pscustomobject]@{username='username2';domain='myseconddomain.com';server='mydc.myseconddomain.com'} | |
[pscustomobject]@{username='username3';domain='mythirddomain.com';server='mydc.mythirddomain.com'} | |
) | |
foreach ($account in $accounts) { | |
Write-Host "Resetting $($account.username) on $($account.domain)" | |
Set-ADAccountPassword ` | |
-Identity $account.username ` | |
-OldPassword $oldPass ` | |
-NewPassword $newPass ` | |
-Server $account.server | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment