Saturday, March 16, 2013

Add User to SharePoint Group using PowerShell

Requirement: Add user to SharePoint Group using PowerShell! We've site collections grouped by managed paths such as "Teams", "Projects". Got a requirement to add a user to Members group of all sites under a particular managed path.

How to Add an User to SharePoint Group?
Adding an 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.
    Add User to SharePoint Group using PowerShell
PowerShell script to add user to Groups in SharePoint:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Site path Variable

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

Foreach($site in $SitesColl)
    #Get the default members group
    $MembersGroup = $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 Members group of: $($Site.url)"  

Related Post: How to Add User To SharePoint Site Group Programmatically

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...