none
Get-Credential popupbox still saves credentials even when fields are empty or when your press the Cancel-button. RRS feed

  • Question

  • Dear Experts,

    Get-Credential popupbox still saves credentials even when fields are empty or when your press the Cancel-button. How can i solve this in PowerShell? I have wrote that de credentials will be written to file

    $credentials = Get-Credential  #popup box$filename = 'L:\secretfile.txt'$credentials | Export-CliXml -Path $filename

    gr.P

    Tuesday, November 19, 2019 5:36 PM

Answers

  • Check the credentials returned to see if they are null.

    The answer is a bit tricky due to the use case for the CmdLet. The following is the best you can do in this case.

    Try{ if($cred = Get-Credential -Credential $cred -ErrorAction Stop){ Write-Host good
    Write-Host $cred.Username }else{ Write-Host no creds } } Catch{ Write-Host no creds }



    \_(ツ)_/


    • Edited by jrvModerator Tuesday, November 19, 2019 6:18 PM
    • Marked as answer by PeetK Tuesday, November 19, 2019 6:21 PM
    Tuesday, November 19, 2019 6:17 PM
    Moderator