Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function CredTest($cred, $rekurze){
- $ErrorActionPreference = "Ignore"
- try{#passed cred CAN be $null
- $username = $cred.username
- $password = $cred.GetNetworkCredential().password
- }
- catch{
- }
- $CurrentDomain = "LDAP://" + ([ADSI]"").distinguishedName
- $domain = New-Object System.DirectoryServices.DirectoryEntry($CurrentDomain,$UserName,$Password)
- if ($domain.name -eq $null){
- write-host "Invalid creds." -ForegroundColor Red
- if($rekurze -ne 1){
- Write-Host "Try again"
- $cred = Get-Credential -UserName "domain\" -Message "You need a domain account:";
- CredTest $cred 1 #trying again. Once.
- }
- else{
- Write-Host "Script will be terminated: " -ForegroundColor Red
- [Environment]::Exit(0)
- }
- }
- else{
- write-host "Valid creds. " $cred.UserName -ForegroundColor Green
- return $cred
- }
- }
- $cred = CredTest $cred
- return $cred
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement