Created
July 15, 2020 00:04
-
-
Save mannharleen/bf538f068e850612000a62e7854076c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$cred = Get-Credential #Read credentials | |
$username = $cred.username | |
$password = $cred.GetNetworkCredential().password | |
# Get current domain using logged-on user's credentials | |
$CurrentDomain = "LDAP://" + ([ADSI]"").distinguishedName | |
$domain = New-Object System.DirectoryServices.DirectoryEntry($CurrentDomain,$UserName,$Password) | |
if ($domain.name -eq $null) | |
{ | |
write-host "Authentication failed - please verify your username and password." | |
exit #terminate the script. | |
} | |
else | |
{ | |
write-host "Successfully authenticated with domain $domain.name" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment