Skip to content

Instantly share code, notes, and snippets.

@rufflabs
Created May 23, 2015 14:20
Show Gist options
  • Save rufflabs/983303272c23b982d943 to your computer and use it in GitHub Desktop.
Save rufflabs/983303272c23b982d943 to your computer and use it in GitHub Desktop.
Changes the passsword for a specific user on multiple PC's
# List of hostnames
$computers = 'e:\computerlist.txt'
# Username and password to change to
$Username = ''
$NewPassowrd = ''
$ExistingCredentials = Get-Credential -Message 'Existing credentials'
foreach($Computer in (Get-Content $Computers)) {
echo "Changing: $($Computer)"
$System = New-Object system.directoryservices.directoryentry("WinNT://$($Computer)",$ExistingCredentials.Username,$ExistingCredentials.GetNetworkCredential().Password)
$user = $System.Children.Find($Username, 'user')
$user.setPassword($NewPassword)
$user.setInfo()
$System.close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment