Pnp-powershell: Iterating through site collections using Connect-PnPOnline

Created on 12 Apr 2018  路  5Comments  路  Source: pnp/PnP-PowerShell

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?

Which version of the PnP-PowerShell Cmdlets are you using?

  • [ ] PnP PowerShell for SharePoint 2013
  • [ ] PnP PowerShell for SharePoint 2016
  • [x] PnP PowerShell for SharePoint Online

What is the version of the Cmdlet module you are running?

2.25.1804.1

How did you install the PnP-PowerShell Cmdlets?

  • [ ] MSI Installed downloaded from GitHub
  • [x] Installed through the PowerShell Gallery with Install-Module
  • [ ] Other means

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 -ClearTokenCache

Then for subsequent calls just use
Connect-PnPOnline -Url "https://tenant.sharepoint.com/sites/testsite4" -SPOManagementShell

All 5 comments

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

Was this page helpful?
0 / 5 - 0 ratings