How to Add User to SharePoint Group using PowerShell?
Requirement: Add User to SharePoint Group using PowerShell.
How to add a user to a group in SharePoint 2016?
Adding users to groups is a common task that administrators need to perform to organize and manage permissions in SharePoint environments. In this blog post, we will walk you through the process of adding a user to a SharePoint group. We will also show you how to add a user to a SharePoint group using PowerShell.
Follow the below steps to add a user to a particular group on the SharePoint site:
- Go to your SharePoint site and click on Site Settings gear icon >> Select “Site settings”.
- Click on the “People and groups” link under “Users and Permissions”.
- Click on the SharePoint user group to which you want to add users, such as “Marketing Members”.
- Click on “New” button >> and select “Add Users”.
- Enter the names of the users to add. Make sure all your entries are resolved.
- Click on the “Share” button to complete adding a user to the SharePoint group.
The users you have entered are now part of the SharePoint group! By default, new users receive an email notification, and we can customize the email message text if needed. Also, we can choose not to send an email by clicking Show Options and clearing the “Send an email invitation” checkbox.
Add User to SharePoint group with PowerShell
SharePoint provides two cmdlets to add a user to a group using PowerShell.
The New-SPUser cmdlet adds an existing active directory (or whatever authentication provider) to SharePoint to the appropriate group specified.
New-SPUser -UserAlias "domain\user" -Web "https://sharepoint.crescent.com/sites/marketing" -Group "Marketing Owners"
This will add a new user to the SharePoint site to the particular group. If you execute this command the next time (without deleting the user from site collection), it won’t have any effect!
Set-SPUser cmdlet adds an existing SharePoint user to an existing group on the given site.
Set-SPUser -Identity "domain\user" -Web "https://sharepoint.crescent.com/sites/marketing" -Group "Marketing Owners"
This will add the existing SharePoint user’s account to the provided group but will give an error when you try to add a new user to the SharePoint site. (which is obvious! We can’t set the user property, if the user doesn’t exist on the SharePoint site, isn’t it?)
Add User to SharePoint Group using PowerShell Script
Other than New-SPUser and Set-SPUser cmdlets, let’s use the native object model APIs to add a user to a group in SharePoint using PowerShell.
#Get the Web $web=Get-SPWeb "https://sharepoint.crescent.com/sites/marketing" #Get the SharePoint Group $Group= $web.Groups["Marketing Owners"] $userName = "domain\userName" #Add User to the site collection $user = $web.EnsureUser($UserName) #Add User to the Group $group.AddUser($user)
5 thoughts on “How to Add User to SharePoint Group using PowerShell?”
How about add AD group to SP group – sharepoint 2016 – on premise ?
Use this script: How to Add Active Directory Group to SharePoint Group?
Line 4 should be $web.SiteGroups
add users to sharepoint library/list in bulk from CSV file???