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

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()
    }
}
  • My code fails when .site groups.add() with owner., member parameters – SaMolPP May 12 '15 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. – SaMolPP May 12 '15 at 0:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.