2020 | Scott W. Head  |  Sr. Systems Admin | Certified Microsoft Windows Server Administrator

PowerShell Local Account Password Reset

<# 

    .SYNOPSIS     
    Script to reset account password on local account on remote machines

    .DESCRIPTION 
    This can be used to query some computers and reset password on a account

    .EXAMPLE  
    Enter account information at prompt
#>


$MyCommand={

 #Paramater for inbound Data
    Param($PassedArray) 
    
    Try {
      $account = [ADSI]("WinNT://$Env:ComputerName/$($PassedArray[0]),user")
      $account.psbase.invoke("setpassword",$PassedArray[1])
      Return "`tPassword Change completed successfully"
    }
    Catch {      
      Return "`tFailed to Change the administrator password. Error: $_"
    }
}

#Decalre Array to Pass
$PassedArray=@()
#Get Input From Users
$PassedArray+= Read-host "Enter Local Account"
$PassedArray+= Read-Host "Enter New Password"
$ServerName =  Read-Host "Enter Server Name"

#Execute Command 
Invoke-Command $ServerName -ScriptBlock $MyCommand -ArgumentList @(,$PassedArray)