Tech

How to Add Users to Multiple SharePoint Online Site Collections Using SharePoint PowerShell

Introduction

Managing user access across multiple SharePoint Online site collections can be time-consuming when done manually. Using the SharePoint Online Management Shell, administrators can efficiently add users to multiple sites in bulk using PowerShell.

Prerequisites

  • SharePoint Online Management Shell installed

  • SharePoint Admin role

  • Global Admin (if required)

Install module (if needed):

Install-Module Microsoft.Online.SharePoint.PowerShell

Connect to SharePoint Online

$adminUrl = "https://yourtenant-admin.sharepoint.com"
Connect-SPOService -Url $adminUrl

Add User to a Single Site Collection

$siteUrl = "https://yourtenant.sharepoint.com/sites/Finance"
$user = "user@domain.com"

Set-SPOUser -Site $siteUrl -LoginName $user -IsSiteCollectionAdmin $false

To add as Site Collection Admin:

Set-SPOUser -Site $siteUrl -LoginName $user -IsSiteCollectionAdmin $true

Add User to Multiple Site Collections (Bulk)

Option A – Using an Array

$user = "user@domain.com"

$sites = @(
    "https://yourtenant.sharepoint.com/sites/Finance",
    "https://yourtenant.sharepoint.com/sites/HR",
    "https://yourtenant.sharepoint.com/sites/IT"
)

foreach ($site in $sites) {
    Write-Host "Adding user to $site"
    Set-SPOUser -Site $site -LoginName $user -IsSiteCollectionAdmin $false
}

Option B – Using CSV (Recommended for Large Environments)

CSV File (sites.csv):

SiteUrl
https://yourtenant.sharepoint.com/sites/Finance
https://yourtenant.sharepoint.com/sites/HR
https://yourtenant.sharepoint.com/sites/IT
$user = "user@domain.com"
$sites = Import-Csv "C:\sites.csv"

foreach ($site in $sites) {
    Write-Host "Adding user to $($site.SiteUrl)"
    Set-SPOUser -Site $site.SiteUrl -LoginName $user -IsSiteCollectionAdmin $false
}

Verify user access

Get-SPOUser -Site "https://yourtenant.sharepoint.com/sites/Finance"

 

 

Related Articles

Leave a Reply

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

Back to top button