PowerTip: Store PowerShell Credentials

PowerTip: Store PowerShell Credentials

  • Comments 2
  • Likes


Summary: Store your Windows PowerShell credentials in a variable for later use.

Hey, Scripting Guy! Question How can I store alternate credentials for repeated use in my Windows PowerShell session?

Hey, Scripting Guy! AnswerUse the Get-Credential cmdlet to prompt for a credential, and store the results in a variable:

$credential = Get-Credential


Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Using this now to aleviate the multiple logon's with our functions-

    Example -

    $c = get-credential MyDomain\MyUserId

    # Load Lync

    function bsp-lync


    $newlyncsession = New-PSSession -ConnectionUri mydomain-lyncpool.domain/ocspowershell -credential $c

    import-pssession -session $newlyncsession


  • @Tim Bolton Thank you for sharing this. Awesome idea.