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

PowerShell Local Account Password Check

<#  
    .SYNOPSIS
        Check Password on a Local Account on Remote Machine
    
    .DESCRIPTION
        Sometimes you need to check a password on remote machne
    
    .NOTES 
        Requires rights on the remote machine.     
#>


#====================================
# Command Executed on Remote Machine
#====================================

$TestPassword={

    #Paramater for inbound Data
    Param($PassedArray) 

    Add-Type -AssemblyName System.DirectoryServices.AccountManagement
    $obj = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('machine',$Env:Computername)

    $PasswordResetResult=$obj.ValidateCredentials($PassedArray[0], $PassedArray[1])
 
    If($PasswordResetResult){
        $PasswordResetResultText="Account / Password Check Passed"
    }Else{
        $PasswordResetResultText="Account / Password Check Failed"
    }
    return $PasswordResetResultText
}

#Decalre Array to Pass
$PassedArray=@()

#Get Input From Users
$PassedArray+= Read-host "Enter Accounts to Check"
$PassedArray+= Read-Host "Enter Password"
$ServerName=   Read-host "Enter Server Name"

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