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.