Confirming/Validating PowerShell Get-Credential Input Before Use - Sample (v1.0)

Provides a way to confirm credentials supplied to Get-Credentials are validated by Active Directory (AD). If they aren't, because of for example a mis-typed password, it will tell you the reason and give you a set number of additional attempts to try again before giving up.

 
 
 
 
 
5 Star
(3)
560 times
Add to favorites
4/29/2019
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • ValidateCredentials always returns false
    1 Posts | Last post April 26, 2019
    • The userName parameter to the PrincipalContext.ValidateCredentials Method [1] should not contain the domain, otherwise the call will always fail.  See the Remarks section:
      
        The userName argument in both overloads of this method must
        take the form username (for example, mcampbell) rather than
        domain\username or username@domain.
      
      [1] https://docs.microsoft.com/en-us/dotnet/api/system.directoryservices.accountmanagement.principalcontext.validatecredentials?view=netframework-4.8
  • Feature Request
    1 Posts | Last post November 01, 2018
    • Tested out your script and it's a great first run! But I noticed a few opportunities within the script. 
      
      After the user is prompted to put their credentials in, the code hits AD to check the $Credentials payload. However, if the user enters no password, or closes the window, AD will still get hit. I found $credentials.password is System.Security.SecureString, so I myself am not sure how to check if the password is null or if the exit or cancel button were clicked.