How to test AD credentials with Powershell

Needed a way of testing credentials the easy way. Found it and modified it. Credits go out to those who helped and use it as you want 🙂

You need to have access to the domaincontroller (onsite or though VPN). The things marked in RED are those you need to change to your own values.

Note that the password will be visible and sent in cleartext as it didn’t work with secure password string for some reason.  So internal testing only. 

$userName = Read-Host -Prompt ‘Please enter your username’
$password = Read-Host -Prompt ‘Please enter your password’

# Get your Domain
$domain = new-object DirectoryServices.DirectoryEntry(“LDAP://IP ADRESS OF DC/cn=sites,cn=configuration,dc=DOMAINNAME (WITHOUT .com/.local),dc=.com/.local etc,”DOMAINNAME\$userName”,”$password”)

if ($domain.name -ne $null)
{
write-host “Authenticated!”
}else{
write-host “Not authenticated – Wrong username or Password!”
}
}