Advertisement
Guest User

Untitled

a guest
Aug 4th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. $cred = Get-Credential #Read credentials
  2. $username = $cred.username
  3. $password = $cred.GetNetworkCredential().password
  4.  
  5. # Get current domain using logged-on user's credentials
  6. $CurrentDomain = "LDAP://" + ([ADSI]"").distinguishedName
  7. $domain = New-Object System.DirectoryServices.DirectoryEntry($CurrentDomain,$UserName,$Password)
  8.  
  9. if ($domain.name -eq $null)
  10. {
  11. write-host "Authentication failed - please verify your username and password."
  12. }
  13. else
  14. {
  15. write-host "Successfully authenticated with domain $($domain.name)"
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement