Forum Discussion
Heiko Watz
Dec 19, 2016Iron Contributor
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?
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
- Michael Greene
Microsoft
This is what I have used in the past: https://gallery.technet.microsoft.com/scriptcenter/PowerShell-Credentials-d44c3cde - Jonathan BoykoCopper Contributor
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 }
- Dean_GrossSilver Contributor
This should help https://github.com/SharePoint/PnP-PowerShell/wiki/How-to-use-the-Windows-Credential-Manager-to-ease-authentication-with-PnP-PowerShell
It was written by the very helpful Erwin van Hunen
- Heiko WatzIron ContributorThat’s what I’ve seen at the ESPC16 – but this only works with PnP ?!
- Dean_GrossSilver Contributor
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.
- Zoltan BagyonSteel Contributor
It's not exactly the same you asked for but it does the job so might be helpful: