[PowerShell] Connect-PnPOnline is using cached credentials

Ben SteginkUncategorized1 Comment

The last few days I’ve been battling an issue using the PnP PowerShell Module for SharePoint Online, specefically Connect-PnPOnline -UseWebLogin. I connect to multiple tenants and somehow my credentials were being cached when I would use the -UseWebLogin parameter due to MFA being in use. When I would try to log in to a tenant, it would use these credentials and try to connect me as a guest rather than prompt me to enter credentials.

Several posts recommended clearing the IE Cache, starting a fresh PowerShell session, etc. None of these worked. I cleared the cache of every browser on the machine, check the stored credentials in windows. Restarted Powershell, restarted the computer, etc.

Finally, I came across this thread – https://github.com/SharePoint/PnP-PowerShell/issues/1656 after reading the comments and playing around a bit I discovered a solution

The Solution

Run the following PowerShell:

You can’t actually clear the token cache while using -UseWebLogin and if you’re connecting to the SPOManagementShell, you can’t necessarily interact with sites, lists, libraries, etc the way you may need to. However, the sequence of comments above allowed me to sucesfully stop using the cached credentials (or token) and enabled me to enter the username/password combination I wanted to use when connecting to SharePoint Online.