Need help with Get-Credential

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 : (:slight_smile: [Get-Credential], ParameterBindingValidationException
  • FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.GetCredenti

Using -ErrorAction SilentlyContinue doesn’t change anything.


Thanks in adanace for your help.


Best regards




You might use a try catch block.

Thanks Olaf

It works now


Best regards