Guest User

Untitled

a guest
Nov 15th, 2018
757
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. $userName = $args[0]
  2. $password = $args[1]
  3. $hostName = $args[2]
  4. Add-Type -AssemblyName System.DirectoryServices.AccountManagement
  5. Function Validate-Credentials{
  6. $principalContext = New-Object System.DirectoryServices.AccountManagement.PrincipalContext("Machine","$hostname")
  7. $validate=$principalContext.ValidateCredentials($userName, $passWord)
  8. if($validate) {
  9. return $true
  10. }
  11. elseif($validate -eq $false) {
  12. throw "Bad username or Password"
  13. }
  14. else {
  15. throw $_.Exception.InnerException
  16. }
  17. }
  18. try {
  19. Validate-Credentials
  20. }
  21. catch {
  22. throw $_.Exception.InnerException
  23. }
Add Comment
Please, Sign In to add comment