Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How to add a New User to SharePoint Group using Powershell Script
WhatsApp
Gowtham Rajamanickam
10y
46.1
k
0
0
25
Blog
Steps
Start your windows PowerShell on your computer.
Right click and select Run as administrator option.
Paste the below script on the PowerShell window and click the enter button.
Check your SharePoint site Feature will activated successfully.
if
((Get-PSSnapin
"Microsoft.SharePoint.PowerShell"
-ErrorAction SilentlyContinue) -eq $
null
)
{
Write-Host
"Connect Sharepoint cmd-Let"
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
$url =
"http://gauti.sharepoint.com"
$site =
new
-object Microsoft.SharePoint.SPSite($url)
$web = $site.OpenWeb()
$groups = $web.sitegroups
$userName =
"username\Domain"
write-host
"--------------"
$i = 0;
$myGroups = @();
foreach($group
in
$groups) {
if
($group -match
"admin"
)
{
$myGroups += $group
}
}
foreach ($gr
in
$myGroups)
{
write-host $gr
#add user to SP Group
Set-SPUser -Identity $userName -web $url -Group $gr
$theGroup = $web.SiteGroups[$gr]
$theUser = $web.AllUsers.Item($userName)
#Remove user from SP Group
# $theGroup.RemoveUser($theUser);
write-host
"User "
$userName
"added to "
$gr
}
Run the script with the required administrator privilege.To verify that, go the group chec user added or not.
Thanks For reading.
How to add a New User to SharePoint Group using Powershell Script
People also reading
Membership not found