1

How to create a SPGroup in my site collection with no permission level assigned using PowerShell. I have created the below script. But it fails to create SPGroup.

      foreach($groupName in $DisciplineGroups)
       {
        if ($mRootWeb.SiteGroups[$groupName] -ne $null)
         {
             Write-Host "Group "$($groupName)" already exists!"
             Break;
         }
       else
       {

        $mRootWeb.SiteGroups.Add($groupName, $mWeb.SiteUsers
         ["domain\myidd.dev"], $null, $description)  

        Write-Host " group  been created  
         on the root web $($mWeb.Title) with $($mWeb.url)"
          $group = $mRootWeb.SiteGroups[$groupName]

        $roleAssignment = new-object Microsoft.SharePoint.SPRoleAssignment
        ($group)

        #$roleDefinition = $web.Site.RootWeb.RoleDefinitions
         #[$permissionLevel]  

        $roleAssignment.RoleDefinitionBindings.Add($roleDefinition)  

        $mRootWeb.RoleAssignments.Add($roleAssignment) 

        $mRootWeb.Update()
       }  

or is this actually possible without a permission level?

1 Answer 1

1

At a glance, if you do not wish to add permissions to the group, don't!

Just do this part:

foreach($groupName in $DisciplineGroups)
{
    if ($mRootWeb.SiteGroups[$groupName] -ne $null)
    {
         Write-Host "Group "$($groupName)" already exists!"
         Break;
    }
    else
    {
        $mRootWeb.SiteGroups.Add($groupName, $mWeb.SiteUsers["domain\myidd.dev"], $null, $description)  
        Write-Host "Group  been created on the root web $($mWeb.Title) with $($mWeb.url)"
        $mRootWeb.Update()
    }
}
2
  • My code fails when .site groups.add() with owner., member parameters Commented May 12, 2015 at 0:39
  • How to pass the SPUser object in this method, though I tried with get-spuser "in\myuseridd" and passed this object I got error null index on array. Commented May 12, 2015 at 0:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.