Posts

Showing posts from September, 2025

Connecting to Multiple SharePoint Sites with a Single Authentication Prompt Using PnP PowerShell

Image
 Context Sometimes, you must perform some activities to multiple SharePoint sites using a script. You would probably be prompted to get connected to each site because of MFA .  In my case, I needed to verify if someone was site owner on multiple sites. Prerequisites You will need  SharePoint Admin  permissions (you may have to elevate your privileges " PIM "). PowerShell and PnP.PowerShell module must be installed. Code Sample In this example, I'm checking if my Entra ID group is member of site Onwers. $siteUrls = Import-Csv -Path $CsvPath $tenantAdminUrl = "https://yourTenant-admin.sharepoint.com" $tenantClientID = "567bf829-465a-ds5e-ad03-0af9f30o5619" $loginName = "c:0t.c|tenant|$aadGroupId" $tenantConnection = Connect-PnPOnline -Url $tenantAdminUrl -ClientId $tenantClientID -Interactive -ReturnConnection foreach ($siteUrl in $siteUrls) { #Connect to the site Connect-PnPOnline -Url $siteUrl -ClientId $tenantClientID ...