Retrieve SharePoint Groups using PowerShell

Disclaimer: This post and function is 100% taken from the book by Gary Lapointe and Shannon Bray entitled “Automating Microsoft SharePoint 2010 Administration with Windows PowerShell 2.0.”

As I frequently do when I’m looking for a topic to blog about, I reach for my favorite tool – PowerShell. Over the weekend I was reading some of the aforementioned book and I came across a set of tasks which do not have corresponding cmdlets out-of-the-box.

There are a set of functions described in Chapter 8 – Managing Site Collections and Sites which can be created and used to manage SharePoint Groups. There are 3 functions: Get-SPGroup, New-SPGroup and Remove-SPGroup. This post will only focus on the first and easiest, Get-SPGroup.

The Get-SPGroup function is pretty simple, and other than my obligatory comment-based help (which accounts for 23 of the 33 lines 🙂 ) – this function is very short.

Essentially all it’s doing is obtaining the SiteGroups collection property from an SPWeb object and returning the information on the property.

Here’s the function:

function Get-SPGroup {
	Use Get-SPGroup to retrieve a SharePoint Group.
	This function uses the SiteGroups collection property of an SPWeb object to return a specific group and its properties.
	C:\PS>Get-SPGroup -Web http://intranet -Group "Members"
	This example retrieves the properties of the "Members" group in the http://intranet site.
	Name: Get-SPGroup
	Author: Ryan Dennis
	Last Edit: July 18th 2011
	Keywords: Get-SPGroup
#Requires -Version 2.0
$SPWeb = $Web.Read()
$SPGroup = $SPWeb.SiteGroups[$Group]
return $SPGroup

I’ll soon be posting the other two functions…



6 thoughts on “Retrieve SharePoint Groups using PowerShell

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s