PNP-PowerShell with MFA and multiple sites in CSV

Iron Contributor

Hello, I am trying to figure out how to assign Read permissions to a SharePoint Online Group in multiple sitecollection subistes.

 

So far I was able to get this to work, however with PNP and MFA I find I do it ONCE and think I might have to do it again and again.  Is there a way to log on with the site collection and then update the subsites, with MFA, and only log on once?  Maybe use a CSV to scroll through?  SharePoint Group is the same and Read Permission for all of the about 100+ subsites.

 

I know that we want all SiteCollections; this is a migration from on-premises and so it probably will be around for a while.  People don't like change and bookmark everything so to change it would cause issues.  We have a few thousand people on our Tenant.

 

Connect-PnPOnline -Url https://COMPANY-admin.sharepoint.com -UseWebLogin

Connect-PnPOnline –Url https://COMPANY.sharepoint.com/sites/SiteCollection/Subsite –UseWebLogin
Set-PnPGroupPermissions -Identity 'SharePoint Group Name' -AddRole 'Read'

 

I just need to change this, for example:

https://COMPANY.sharepoint.com/sites/SiteCollection/SubsiteA

https://COMPANY.sharepoint.com/sites/SiteCollection/SubsiteB

https://COMPANY.sharepoint.com/sites/SiteCollection/SubsiteC

Yet, I don't want to log on multiple times, I hope to log on once and use the CSV (IF it is the best way to do this), to pull from.  I don't mind pasting in a long Script, if it is better; again, all Read Only, and SharePoint Group.

When migrating over, it was a local domain and that is not on our Microsoft 365 Tenant, so the group didn't "carry over" so I am using a SharePoint Group that does exist.

 

Thank you.

2 Replies
We are running into a similar issue

@Matthew Carter best bet is to generate a Client ID + Secret (or cert) to connect to the sites without requiring MFA, i.e. https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/connect-pnponline?view=sharepoint-....