kwizcom banner advertisement

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 Owner/Members group of all sites under a particular managed path.

How to Add a User to 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 SharePoint site
  • Click on "People and Groups" link under Users and Permissions
  • Pick the Relevant group from Left navigation
  • Click on "New" and choose "Add Users"
  • Enter the Name of the user, Optionally select "Send an email invitation" checkbox and click on "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
Add a User to Owner Group of All SharePoint Sites using PowerShell Add a User to Owner Group of All SharePoint Sites using PowerShell Reviewed by Salaudeen Rajack on 2:00 PM Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.