Need help with Get-Credential

Welcome Forums General PowerShell Q&A Need help with Get-Credential

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
1 week ago.

  • Author
    Posts
  • #133824

    Participant
    Points: -6
    Rank: Member

    Hi there

     

    I'm trying to use this syntax:

    $cred = Get-Credential -Credential $env:UserName

     

    This works, but when I use the cancel-button I get the follwing error:

    Get-Credential : Impossible de lier l'argument au paramètre « Credential », car il a la valeur Null.
    Au caractère C:\Users\xxxxxx\Documents\Dimo\PS1\AD\Check_User_Password.PS1:2 : 36
    + $cred = Get-Credential -Credential $env:UserName -ErrorAction Silentl ...
    + ~~~~~~~~~~~~~
    + CategoryInfo : InvalidData : (:) [Get-Credential], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.GetCredenti
    alCommand

    Using -ErrorAction SilentlyContinue doesn't change anything.

     

    Thanks in adanace for your help.

     

    Best regards

     

    Ossy

     

  • #133838

    Participant
    Points: 412
    Helping Hand
    Rank: Contributor

    You might use a try catch block.

  • #133850

    Participant
    Points: -6
    Rank: Member

    Thanks Olaf

    It works now

     

    Best regards

You must be logged in to reply to this topic.