Skip to content

Instantly share code, notes, and snippets.

@petarvucetin
Created April 2, 2015 16:02
Show Gist options
  • Save petarvucetin/19e9f8b5207eb5f6e896 to your computer and use it in GitHub Desktop.
Save petarvucetin/19e9f8b5207eb5f6e896 to your computer and use it in GitHub Desktop.
PS: Validate-Credentials
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