Created
April 2, 2015 16:02
-
-
Save petarvucetin/19e9f8b5207eb5f6e896 to your computer and use it in GitHub Desktop.
PS: Validate-Credentials
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
function Validate-Credentials([System.Management.Automation.PSCredential]$credentials) | |
{ | |
$ct = [System.DirectoryServices.AccountManagement.ContextType]::Domain | |
$nc = $credentials.GetNetworkCredential() | |
$principal = $nc.Domain.ToString() + "\"+ $nc.UserName.Tostring() | |
$pctx = New-Object System.DirectoryServices.AccountManagement.PrincipalContext($ct, "axaros.com") | |
return $pctx.ValidateCredentials($nc.UserName, $nc.Password) | |
} | |
$LogedOnUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name; | |
$currentUser = $host.ui.PromptForCredential("Need credentials", "Application Pool Identitiy", $LogedOnUser, "NetBiosUserName") | |
if (!(Validate-Credentials $currentUser)) | |
{ | |
thorw "UPN is not correct" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment