Skip to content

Instantly share code, notes, and snippets.

@mattvanstone
Last active July 13, 2019 17:13
Show Gist options
  • Save mattvanstone/4f40ebcc903b5396cfa01fcc70237889 to your computer and use it in GitHub Desktop.
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
# 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