Test Local User Account Credentials

by | July 10,2013

Table of Contents

Verifying a Local User Account

Here is a snippet that verifies a local user account. Simply submit a username and a password. You get back either $true or $false:

$username = 'Administrator'
$password = 'P@ssw0rd'

$computer = $env:COMPUTERNAME

Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$obj = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('machine',
$computer)
$obj.ValidateCredentials($username, $password) 

 

ReTweet this Tip!