Showing posts with label Groups. Show all posts
Showing posts with label Groups. Show all posts

Monday, June 4, 2012

Creating default associated groups

While creating a new site through the UI (Site Actions->New Site) my browser crashed. This caused the default associated groups to not get created among other things. As a result, I had to do this manually.

Looking back at a previous post, Creating predefined groups in site collection created by Powershell, I ran the following Powershell:

$web.CreateDefaultAssociatedGroups($web.Site.Owner.UserLogin, $web.Site.SecondaryContact.UserLogin, $web.Title)


I went back into Site Permissions and still didn't see my groups. Reading the SPWeb.CreateDefaultAssociatedGroups Method document's Remarks, it mentions that the AssociatedVisitorGroup and the AssociatedOwnerGroup have to be null before invoking this method. Mine were set to point to the equivalent Home groups. So I ran the following:
$web.AssociatedOwnerGroup = $null
$web.AssociatedMemberGroup = $null
$web.AssociatedVisitorGroup = $null
$web.CreateDefaultAssociatedGroups($web.Site.Owner.UserLogin, $web.Site.SecondaryContact.UserLogin, $web.Title)

and all is fine.

Wednesday, May 16, 2012

Remove site groups

I regularly create webs and subwebs with non-inherited permissions. This results in a bunch of permissions groups created for those webs. For some reason, deleting the web does not remove the corresponding groups. Since sometimes there are a lot, I decided to write a script to do this:

$web = Get-SPWeb <URL of root web>
$groupstodelete = $web.SiteGroups | Where-Object {$_.Name -eq "<whatever matching criteria>"}
$groupstodelete | ForEach-Object {$web.SiteGroups.Remove($_.Name)}

Simple and saves me a lot of clicking

Thursday, September 15, 2011

SharePoint default members group

I recently had to try to determine the SharePoint Default Members Group of a particular site. In Site Actions->Site Permissions, you can go to a group and then click Make Default Group. What's bizarre is that there is no indication which group is default, at least not in the UI. The only way I could find is in PowerShell as follows:
$web = Get-SPWeb <myurl>
$web.AssociatedMemberGroup

or you can get the ID through the property bag at
$web.Properties["vti_associatemembergroup"]

Not sure which way is better, but either works for me so far. It would also be nice to see it in the UI.

Thursday, January 6, 2011

Creating predefined groups in site collection created by Powershell

Here's another discrepancy between what the UI does and what the Powershell scripts seem to do. As I'm in the process of scripting a manual creation process, one of the things I want to do is create a site collection. Looking at Technet you get instructions to Create a site collection (SharePoint Server 2010).

However, doing it via Central Administration vs via Powershell has a slight difference. If you create your site collection via the web UI you get a handful of SharePoint groups automatically created, but not if you create it via Powershell.

With the Powershell approach, there are "No predefined Groups in sitecollection created with Powershell". All you need to do is to call the CreateDefaultAssociatedGroups() method of the SPWeb object.

Here's the code I used:

New-SPSite -Url $sp_sc_url -Name $sp_sc_name -Template $sp_sc_template -OwnerAlias $sp_sc_owner -SecondaryOwnerAlias $sp_sc_owner2 -Language $sp_sc_language
$sp_web = Get-SPWeb $sp_sc_url
$sp_web.CreateDefaultAssociatedGroups($sp_sc_owner, $sp_sc_owner2, "")