Need to iterate through all the site collections to get information about lists. User has MFA enabled. How to connect using connect-pnponline without having to enter credentials every time connect-pnponline is called?
2.25.1804.1
Have you tried using the -SPOManagementShell switch which should store a token valid until it expires?
Could you please share some sample? I am getting error "forbidden" when using -spomanagementshell
Try adding -cleartokencache as well for your first connection. Or try to use app password for the mfa account.
I think I'm missing something, from the documentation it's not clear how to exactly connect using -SPOManagementShell.
Did you mean like this -
Connect-PnPOnline -Url "https://tenant.sharepoint.com/sites/testsite3" -SPOManagementShell -ClearTokenCache
Then for subsequent calls just use
Connect-PnPOnline -Url "https://tenant.sharepoint.com/sites/testsite4" -SPOManagementShell
Tested with above. Seems to be working. Considering that's the right way to use -SPOManagementShell
Most helpful comment
I think I'm missing something, from the documentation it's not clear how to exactly connect using -SPOManagementShell.
Did you mean like this -
Connect-PnPOnline -Url "https://tenant.sharepoint.com/sites/testsite3" -SPOManagementShell -ClearTokenCacheThen for subsequent calls just use
Connect-PnPOnline -Url "https://tenant.sharepoint.com/sites/testsite4" -SPOManagementShell