Created
May 23, 2015 14:20
-
-
Save rufflabs/983303272c23b982d943 to your computer and use it in GitHub Desktop.
Changes the passsword for a specific user on multiple PC's
This file contains hidden or 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
# 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