Steps
Start your Windows PowerShell on your computer.
Right click and select run as an administrator option.
Paste the script given below on PowerShell Window and click enter button.
Check that your SharePoint site feature will be activated successfully.
Syntax Explanation
Add-SPGroup -webUrl "http://gowtham.sharepoint.com"
-groupName "SharePointOwner"
-description "SPOwners"
-ownerName "spdev\gowtham"
-defaultMemberName "spdev\gowtham" `\
-membership "spdev\gowtham"
- function Add-SPGroup {
-
-
- [CmdletBinding()]
- Param(
- [Parameter(Mandatory=$true)][string]$webUrl,
- [Parameter(Mandatory=$true)][string]$groupName,
- [Parameter(Mandatory=$true)][string]$description,
- [Parameter(Mandatory=$true)][string]$ownerName,
- [Parameter(Mandatory=$true)][string]$defaultMemberName,
- [Parameter(Mandatory=$true)][string]$membership
- )
- try {
-
- Write-Host "Checking Group already exists"
- $web = Get-SPWeb $webUrl;
- $spGroup = $web.SiteGroups[$groupName];
-
- if ($spGroup -ne $null) {
- Write-Warning "Group $groupName already exists in this site!";
- return $spGroup;
- }
-
- $owner = $web.EnsureUser($ownerName);
- $member = $web.EnsureUser($defaultMemberName);
-
- Write-Host "Creating Group"
- $web.SiteGroups.Add($groupName, $owner, $member, $description);
- $spGroup = $web.SiteGroups[$groupName];
-
- Write-Host "Adding users to Group"
- $usersToAdd = $membership.split(",");
- foreach($user in $usersToAdd) {
- $ensuredUser = $web.EnsureUser($user.trim());
- $spGroup.AddUser($ensuredUser);
- }
-
- $web.RoleAssignments.Add($spGroup);
- $web.Dispose();
- return $spGroup;
- }
- catch {
-
- Write-Error $Error[0];
- } }
Thanks for reading the blog.