Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. ##
  2. ## @file ChangePassword.ps1
  3. ## @author Drew Chapin <drew@drewchapin.com>
  4. ## @brief Script to change local password on multiple remote computers.
  5. ##
  6.  
  7. function Get-Password( $prompt )
  8. {
  9. $pw = Read-Host $prompt -AsSecureString
  10. return [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($pw))
  11. }
  12.  
  13. $login_username = Read-Host "Login Username"
  14. $login_password = Get-Password("Login Password")
  15. $update_username = Read-Host "Update Username"
  16. $update_password = Get-Password("New Password")
  17. $confirm = Get-Password("Confirm Password")
  18.  
  19. if( $update_password -ne $confirm )
  20. {
  21. Write-Host "New password confirmation failed. Please try again."
  22. exit
  23. }
  24.  
  25. $computers = @("HOSTNAME1","HOSTNAME2","HOSTNAME3")
  26.  
  27. foreach( $computer in $computers )
  28. {
  29. Write-Host " [ -- ] $computer" -NoNewLine
  30. try
  31. {
  32. $entry = New-Object System.DirectoryServices.DirectoryEntry("WinNT://$computer/$update_username",$login_username,$login_password)
  33. $entry.Invoke("SetPassword",$update_password)
  34. Write-Host "`r [ OK ]" -ForegroundColor "green"
  35. }
  36. catch
  37. {
  38. Write-Host "`r [FAIL]" -ForegroundColor "red"
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement