Recently I got a requirement from a customer, they want to assign edit permissions to few users on multiple sites. It would be easy to go to the site permissions and add users to the edit permission group or assign edit permissions using PowerShell. This could be simple when you have to add users to a few sites but it would be a time consuming job when you have to add different users to a large no. of site collections.

To make the permissions clean, I have written a small PowerShell script which fetch the site security groups and verify the security group with Edit role and users to that group.

$TenantUrl = "https://<site URL>"
$CSVPath = "D:\Migratedsites.csv"

Connect-SPOService -Url $TenantUrl

$Useraccounts = @("","","")

$SiteCollections = Import-Csv -Path $CSVPath
    #Loop through csv and create site collections from each row
    ForEach ($Site in $SiteCollections)
        $siteUrl = $Site.URL
        Write-host "Creating Site Collection:" $siteUrl -f Yellow
        $group = Get-SPOSiteGroup -site $siteUrl | Select Title, Roles, Users  | Where-Object {$_.Roles -eq "Edit"}
        ForEach($UserAccount in $Useraccounts)
          Add-SPOUser -Site $siteUrl  -Group $group[0].Title -LoginName $UserAccount

          Write-host $siteUrl "`t users added successfully!" -f Green

Similarly, you can add users to site Owners and read-only groups.

Adnan is six time Microsoft MVP (Since 2015) with over 16 years of extensive experience with major expertise on SharePoint, SharePoint based development, Microsoft 365, Microsoft Teams, .Net Platform and Microsoft BI. He is currently working Sr Microsoft Consultant at Olive + Goose. He is MCT Regional Lead for Pakistan Chapter since 2012. He is working on SharePoint for past 12 years and worked on different intranet/intranet solutions for private & govt. sector majorly in United states and Gulf region and have experience of working with multiple Fortune 500 companies. He is a trainer, technology evangelist and also speaks in community forums.

Leave a Reply