Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. Import-Module ActiveDirectory
  2. $cred = Get-Credential #Read credentials
  3. $username = $cred.username
  4. $password = $cred.GetNetworkCredential().password
  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. if ($domain.name -eq $null)
  9. {
  10. write-host "Authentication failed - please verify your username and password."
  11. exit
  12. }
  13. else
  14. {
  15. write-host "Successfully authenticated with domain $domain.name"
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement