Advertisement
VanillaGranilla

Test AD credentials.ps1

Jul 11th, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $UserName = Read-Host 'Username?'
  2. $Password = Read-Host 'Password?' -AsSecureString; #In case someone is looking over your shoulder :P
  3. $Domain = Read-Host 'Domain?'
  4. $PasswordAsString = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password))
  5.  
  6. Add-Type -AssemblyName System.DirectoryServices.AccountManagement
  7. $CT = [System.DirectoryServices.AccountManagement.ContextType]::Domain
  8. $PC = New-Object System.DirectoryServices.AccountManagement.PrincipalContext($CT, $Domain)
  9. $IsValid = $PC.ValidateCredentials($UserName, $PasswordAsString).ToString()
  10. "Valid? $IsValid"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement