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

#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

    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 - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

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