Skip to content

Instantly share code, notes, and snippets.

@karbomusic
Created May 4, 2022 14:18
Show Gist options
  • Save karbomusic/3f3825f68ef3dc65c5ef0c2441b5163f to your computer and use it in GitHub Desktop.
Save karbomusic/3f3825f68ef3dc65c5ef0c2441b5163f to your computer and use it in GitHub Desktop.
$domain = "mydomain"
$adminUsername = "someadmin"
$adminPassword = "password"
$targetAccount = "targetAccount"
$newPassword = "NewPassword123"
$path = "LDAP://$domain"
$searchAccount = "(sAMAccountName=$targetAccount)"
# Run via admin account
Write-Output "Changing password..."
$Root = New-Object System.DirectoryServices.DirectoryEntry $path, $adminUsername, $adminPassword
$Search = New-Object System.DirectoryServices.DirectorySearcher $Root, $searchAccount
$Match = $Search.FindOne()
$Entry = $Match.GetDirectoryEntry()
$Entry.UsePropertyCache = $true
$passwordObject = @($newPassword)
$Entry.Invoke("SetPassword", $passwordObject)
Write-Output "Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment