Add a User to Owner Group of All SharePoint Sites using PowerShell

Requirement: Add user to Owner Group of All SharePoint site collections using PowerShell!

We’ve site collections grouped by managed paths such as “Teams”, “Projects”. Got a requirement to add a user to the Owner/Members group of all sites under a particular managed path.

How to add a User to the Owner/Member Group in SharePoint?

Adding a user to any SharePoint group is quite simple. Login as a Site owner, Open the SharePoint site and:

  • Click on “Site Settings Gear” Icon from the SharePoint site
  • Click on the “People and Groups” link under Users and Permissions
  • Pick the Relevant group from the Left navigation
  • Click on “New” and choose “Add Users”
  • Enter the Name of the user, Optionally select the “Send an email invitation” checkbox and click on the “Share” button.
    powershell add user to sharepoint owner group

PowerShell to add a user to SharePoint Owner Group:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Site path Variable
$SitesPath="http://inside.crescent.com/projects/*" 
$UserAccount="i:0#.w|Crescent\DavidP"

#Get all sites under the specific managed path
$SitesColl = Get-SPSite $SitesPath -limit All 

#To get all site collections, use:
#$SitesColl = Get-SPSite -limit All 

Foreach($site in $SitesColl)
{
    #Get the default owner group associated with the site
    $Group = $Site.RootWeb.AssociatedOwnerGroup

    #For Members: $Group = $Site.RootWeb.AssociatedMemberGroup
    #To get a particular group, use: $group = $web.SiteGroups[GroupName];
    
    #Get the User Object
    $user = $web.EnsureUser($UserAccount)
 
    #Add User to the Group
    $Group.AddUser($user)

    Write-Host "User Added to the Owner Group of: $($Site.url)"  
}  

If you are looking for add a user to SharePoint group using PowerShell, refer: How to Add User to SharePoint Group using PowerShell?

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply