Bulk Updating Site Collection Properties using PnP PowerShell

Loading

Managing multiple SharePoint Online site collections can be time-consuming, especially when updating properties like storage quota, sharing settings, site classification, or site administrators. Using PnP PowerShell, you can efficiently update multiple site collections in bulk with minimal effort.

In this guide, we will walk through step-by-step instructions on how to bulk update site collection properties using a CSV file and PnP PowerShell.


Prerequisites

Before performing bulk updates, ensure the following:

You have Global Admin or SharePoint Admin permissions.
You have installed PnP PowerShell.
You have a CSV file with site URLs and properties to update.


Step 1: Install and Import PnP PowerShell

If you haven’t installed PnP PowerShell, install it using:

Install-Module -Name PnP.PowerShell -Scope CurrentUser -AllowClobber -Force

Then, import the module:

Import-Module PnP.PowerShell

Step 2: Connect to SharePoint Online

Before updating site collections, connect to the SharePoint Online Admin Center:

Connect-PnPOnline -Url "https://yourtenant-admin.sharepoint.com" -Interactive

Replace "yourtenant" with your actual tenant name.

For app-based authentication, use:

Connect-PnPOnline -Url "https://yourtenant-admin.sharepoint.com" -ClientId "Your-App-Client-ID" -Tenant "yourtenant.onmicrosoft.com" -CertificatePath "Path\To\Certificate.pfx"

Step 3: Prepare a CSV File with Site Properties

To bulk update site collections, create a CSV file (SitesToUpdate.csv) with the required properties.

Example CSV File Format

UrlStorageQuotaSharingCapabilitySiteOwner
https://yourtenant.sharepoint.com/sites/Site1204800ExternalUserSharingOnlyuser1@yourtenant.com
https://yourtenant.sharepoint.com/sites/Site2102400ExistingExternalUserSharingOnlyuser2@yourtenant.com
https://yourtenant.sharepoint.com/sites/Site351200Disableduser3@yourtenant.com

Columns Explained:

  • Url → SharePoint site URL
  • StorageQuota → Storage limit in MB
  • SharingCapability → External sharing settings
  • SiteOwner → New primary owner for the site

Save the file as SitesToUpdate.csv in an accessible location (e.g., C:\Scripts\SitesToUpdate.csv).


Step 4: Bulk Update Site Properties Using PnP PowerShell

Now, run the following PnP PowerShell script to update site properties in bulk:

# Define CSV File Path
$csvFile = "C:\Scripts\SitesToUpdate.csv"

# Import CSV File
$sites = Import-Csv -Path $csvFile

# Loop through each site and update properties
foreach ($site in $sites) {
Write-Host "Updating site: $($site.Url)" -ForegroundColor Cyan

# Update site collection properties
Set-PnPTenantSite -Url $site.Url -StorageQuota $site.StorageQuota -SharingCapability $site.SharingCapability

# Set new Site Owner
Set-PnPSiteOwner -Url $site.Url -Owner $site.SiteOwner

Write-Host "Updated successfully: $($site.Url)" -ForegroundColor Green
}

# Disconnect session
Disconnect-PnPOnline

Write-Host "Bulk update completed!" -ForegroundColor Yellow

This script will:
Read the CSV file.
Loop through each site and update storage quota, sharing settings, and site owner.
Display success messages after updating each site.
Disconnect from SharePoint Online.


Step 5: Verify Updates

After running the script, verify that the changes were applied correctly.

Option 1: Check in PowerShell

Run the following command to list updated properties:

Get-PnPTenantSite -Url "https://yourtenant.sharepoint.com/sites/Site1" | Select-Object Url, StorageQuota, SharingCapability, Owner

🔹 Modify the URL to check other sites.

Option 2: Check in SharePoint Admin Center

1️⃣ Navigate to SharePoint Admin Centerhttps://yourtenant-admin.sharepoint.com
2️⃣ Click Active Sites
3️⃣ Locate the updated site and verify its properties


Common Errors & Troubleshooting

ErrorCauseSolution
Set-PnPTenantSite : Access DeniedYou don’t have SharePoint Admin permissionsEnsure you are a Global Admin or SharePoint Admin
The term 'Set-PnPTenantSite' is not recognizedPnP PowerShell is not installed or importedRun Import-Module PnP.PowerShell
Cannot connect to SharePoint OnlineAuthentication issueUse -Interactive login or App-based authentication
Invalid SharingCapability valueIncorrect value in CSVUse one of the valid values (Disabled, ExistingExternalUserSharingOnly, ExternalUserSharingOnly, ExternalUserAndGuestSharing)

Leave a Reply

Your email address will not be published. Required fields are marked *