Skip Ribbon Commands
Skip to main content

Quick Launch

Todd Klindt's home page > Todd Klindt's Office 365 Admin Blog > Posts > How to Store Windows Credentials with the PnP PowerShell
July 01
How to Store Windows Credentials with the PnP PowerShell

A few months ago I wrote one of my favorite blog posts, Connecting to Office 365 with Multiple Accounts in PowerShell without Losing Your Damned Mind and I think it’s safe to say that no damned minds have been lost connecting to multiple Office 365 tenants since. A lesser man might have stopped there. He might have felt his mark on the world was made and he might just bask in the glory of all of that love and adoration. Not this guy. Today, I present you an even better way to connect to Office 365 with multiple accounts in PowerShell without losing your damned mind and without loading any additional modules!*

*(as long as you already have the PnP PowerShell module installed, that is)

Between that fateful day and today the delightful folks that work on the PnP PowerShell module have added three cmdlets that work with Stored Credentials, Add-PnPStoredCredential, Get-PnPStoredCredential, Get-PnPStoredCredential.


While the PnP cmdlets themselves have been able to pull credentials directly out of the Credential Store you still needed an external module to pull credentials out for use with other modules, namely the Azure AD and MSOnline modules and the SharePoint Online module. I previously met that need with the Credential Manager module. Let’s see how it looks.

Use the Get-PnPStoredCredential cmdlet to retrieve a stored credential by name. I’ve only had it work if I specify the –Type parameter with the PSCredential value.

$creds = Get-PnPStoredCredential -Name MODAdmin -Type PSCredential

You can output the $creds object to make sure it it grabbed the account you expected. Then you can pass that object to another cmdlet, like Connect-AzureAD and use it to authenticate.

Connect-AzureAD -Credential $creds

Here’s how it looks.


I haven’t loaded the Credential Manager module since the stored credential cmdlets showed up in the PnP Module. I already have the PnP module installed everywhere, so it seems unnecessary.

Happy Credential Storing.




Thank you for the post

Was trying to figure out why I was getting errors.  the Type tip fixed it.  Thank you for your work.
 on 9/10/2020 6:25 PM

Re: Thank you for the post

Awesome! Well done! I'm glad you figured it out. Isn't using stored credentials the best?

Todd O. KlindtNo presence information on 9/13/2020 10:14 AM

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.


Body *

Today's date *

Select a date from the calendar.
Please enter today's date so I know you are a real person


Want a message when I reply to your comment? Put your Twitter handle here.