Store password in Windows credential manager and use it in Powershell


On the #ESPC16 in Vienna someone is showing a way to store credentials in the Windows credential manager and then use is in Powershell to connect to Exchange / SharePoint / Azure… online.

It was a very simple and I will use it for some scheduled tasks.


But i don’t remember how he does it and I didn’t find such a good and simple way in the net.


Anyone has it also seen or use it before?

8 Replies

I am using the PasswordVault module for this, and it works pretty great.


I wrote a tiny, crude function that would allow me to export a saved credential to a $CurrentCredential variable to use for automation and such:


function Save-CredentialToVariable ($CredentialLookupString)
######## This function saves a credential from vault to a variable
		$global:CurrentCredential = Get-VaultCredential | Where-Object {$_.Resource -match $CredentialLookupString} | ConvertTo-Credential
That’s what I’ve seen at the ESPC16 – but this only works with PnP ?!

Sorry, i can't answer that question. Maybe @Erwin van Hunen can provide some additional insight about how to use this approach with other modules.

best response confirmed by Heiko Watz (Contributor)

We use a class which is available in the PnP Core module to use retrieve credentials from the Windows Credential Manager. That class you can find here :


This would require you to either rewrite that to PowerShell, or use the PnP Core assembly in your project (or simply copy over this class to your own binary PowerShell module code).


Alternatively you could install the PnP PowerShell cmdlets (install-module sharepointpnppowershellonline) and forget about all the other cmdlets and use:


Get-PnPStoredCredential -Name "nameofthecredential" -Type PSCredential


PnP PowerShell is the best solution ever :)
Thank you @Erwin van Hunen

PnP PowerShell rocks!