The last few days I’ve been battling an issue using the PnP PowerShell Module for SharePoint Online,
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
Run the following PowerShell:
Connect-PnPOnline -SPOManagementShell -Url https://mytenant.sharepoint.com -ClearTokenCache
Connect-PnPOnline -Url https://mytenant.sharepoint.com/site/somesite -UseWebLogin
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.