Change local admin password with PowerShell

Change local admin password on multiple machines with PowerShell.

$computers = "srv1","srv2","srv3"
$adminPassword = "PAssW00rrrDdd123"
$logfile = "log.txt"
$ErrorActionPreference = 'stop'
ForEach ($computerName in $computers){
        Try { 
            
             $adminUser = [ADSI] "WinNT://$computerName/Administrator,User"
             $adminUser.SetPassword($adminPassword)

        } 
        Catch { 
            "$(get-date) :: Server:$($computerName) :: $($error[0].exception)" | Out-File -append $logfile                                          
        } 
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *