Reset Local Administrator Password to entire OU

Hello guys,

Recently, I have invested too much effort to make following PowerShell script.

This script provides you the ability to reset passwords to all local administrator users per organization united you stated il the file, you can do that also using one of PSEXEC tools or any other third party tools. the easiest way I found is through PowerShell.

Not only, as soon as it finishes you’ll get a log file with the following data:

Computer name – Success reset password

Computer name –  failed because the network path was not found

Or

Computer name – Access is denied

Import-Module ActiveDirectory
$computers = Get-ADComputer -SearchBase "OU=Users,OU=PelegIT,DC=Peleg,DC=com" -Filter * -Properties name | select name
$password = Read-Host -prompt "Enter new password for user" -assecurestring
$decodedpassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))

"----------------------"+, (Get-Date -format f) +"Ran by"+ (whoami) >> C:\IL-OU.txt


Foreach ($computer in $computers.name)

    {
        Try
        { 

         $user = [adsi]"WinNT://$computer/administrator,user"
         $user.SetPassword($decodedpassword)
         $user.SetInfo()

         $result= "($Computer) administrator account reset"
         Write-Host $result

        }

         Catch
         {

         $Errormessage = $_.Exception.Message
         $result = "($computer) ($Errormessage)"
         
         if ($Errormessage -like '*Access is denied*')
         {
         $result= $computer +" Access is denid" 
         }
         elseif($Errormessage -like '*The network path was not found*')
         {
         $result= $computer + " The network path was not found"
         }
         }
 
    $result >> C:\Report.txt
        
    }


Look at the log:

reset-local-administrator-password-to-entire-ou

About Meir Peleg 338 Articles
My name is Meir Peleg, (Born 30/04/1991) live in ISRAEL. Live and breath IT world. Microsoft MVP Windows IT & VMware vExpert.