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>-admin.sharepoint.us"
$CSVPath = "D:\Migratedsites.csv"

Connect-SPOService -Url $TenantUrl

$Useraccounts = @("AdeleV@mstechtalkdemodev.onmicrosoft.com","alexW@mstechtalkdemodev.onmicrosoft.com","Ben.Jones@mstechtalkdemodev.onmicrosoft.com")

$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"}
        $group[0].Title
        
        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, a distinguished professional, boasts an impressive track record as a Microsoft MVP, having achieved this prestigious recognition for the eighth consecutive year since 2015. With an extensive career spanning over 18 years, Adnan has honed his expertise in various domains, notably excelling in SharePoint, Microsoft 365, Microsoft Teams, the .Net Platform, and Microsoft BI. Presently, he holds the esteemed position of Senior Microsoft Consultant at Olive + Goose. Notably, Adnan served as the MCT Regional Lead for the Pakistan Chapter from 2012 to 2017, showcasing his leadership and commitment to fostering growth within the tech community. His journey in the realm of SharePoint spans 14 years, during which he has undertaken diverse projects involving both intranet and internet solutions for both private and government sectors. His impact has transcended geographical boundaries, leaving a mark on projects in the United States and the Gulf region, often collaborating with Fortune 500 companies. Beyond his roles, Adnan is a dedicated educator, sharing his insights and knowledge as a trainer. He also passionately advocates for technology, frequently engaging with the community through speaking engagements in various forums. His multifaceted contributions exemplify his dedication to the tech field and his role in driving its evolution.

Leave a Reply