VanillaGranilla icon

Test AD credentials.ps1

VanillaGranilla | PRO | 07/11/16 06:22:42 PM UTC | 0 ⭐ | 294 👁️ | Never ⏰ | []
PowerShell |

620 B

|

None

|

0 👍

/

0 👎

$UserName = Read-Host 'Username?'
$Password = Read-Host 'Password?' -AsSecureString; #In case someone is looking over your shoulder :P 
$Domain = Read-Host 'Domain?'
$PasswordAsString = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password))
 
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$CT = [System.DirectoryServices.AccountManagement.ContextType]::Domain
$PC = New-Object System.DirectoryServices.AccountManagement.PrincipalContext($CT, $Domain)
$IsValid = $PC.ValidateCredentials($UserName, $PasswordAsString).ToString()
"Valid? $IsValid"

Comments