PowerTip: Store PowerShell Credentials


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


Comments (2)

  1. mredwilson says:

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

  2. Tim Bolton says:

    Using this now to aleviate the multiple logon’s with our functions-

    Example –

    $c = get-credential MyDomainMyUserId

    # Load Lync

    function bsp-lync


    $newlyncsession = New-PSSession -ConnectionUri
    -credential $c

    import-pssession -session $newlyncsession