Solved

SharePoint 2010 & Powershell: How to narrow down a search to one specific group?

Posted on 2011-02-18
2
816 Views
Last Modified: 2012-05-11
Hello!

I'm attempting to write a PowerShell script for SharePoint 2010 on my development farm.  
With this script, I would like to retrieve a list of anyone who is in a "Members" group.  

So for instance, each site has a "members" group, usually named after the site:
Site Name is "HR", then the group would be "HR Members".
Site Name is "PR", then the group would be "PR Members".
Site name is "Intel", then the group name would be "Intel Members".

This group naming convention is the default naming standard for groups in SharePoint, so hopefully you understand what I'm trying to explain ;-)

The script is attached, and right now it doesn't display anything due to my group name being wrong...I'm just not certain of how to search for PART of a group name (putting a * in front of Members didn't work, so I'm assuming it's a bit more complex).  

This way, I can get a list of all users who are in any group that has the word "Developers" in it, whether it is "SharePoint.Developers", "SharePoint Developers", "Sharepoint-Developers", or "Sharepoint_developers".  

Does anyone see how this might be done?  
0
Comment
Question by:ThatSharepointGuy
2 Comments
 
LVL 38

Accepted Solution

by:
Justin Smith earned 500 total points
ID: 34929410
i don't see the script.....

but are you using a 'where {$_.name -like "*developers*"} ' anywhere ?
0
 
LVL 6

Author Comment

by:ThatSharepointGuy
ID: 34953204
ACH1LLES:

Thanks for the response!  It seems that I was not using the '-like' operator, but instead had '-eq'.  Oops!

I've posted the script below in case anyone else needs it.  Granted, I'm not very savvy at PowerShell, so there might be an easier way to do this, but this is what I have...and it works...but wow...so many groups to sort through! (using this so that I can find out who has dev permissions on each site, in order to create a roster for a contacts list.  Yikes!)  
###################################################################
###	This script goes through all SPSite and SPWeb objects	###
###	and returns the group name and all members of this	###
###	group, as well as the URL to the site that group was	###
###	found at.  It also returns the total number of SPSite	###
###	and SPWeb Objects, number of groups, and # of users.	###
###################################################################

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
## Counting vars.
$siteCount = 0
$webCount = 0
$groupCount = 0
$devCount = 0
$userCount = 0

## Set primary web applicaiton (not central admin / not MySites).
$webApp = Get-SPWebApplication "SP2010_WebApp"

## Iterate through all SPSite objects within the SPWebApplication.
foreach ($site in $webApp.Sites)
{
	## Increment $siteCount.
	$siteCount = $siteCount +1
	
	## Get the total number of SPWebs for each SPSite.
	for($i=0; $i -lt $site.AllWebs.Count; $i++)
	{
		## Increment $webCount.
		$webCount = $webCount +1
 	
		$groups = $site.AllWebs[$i].sitegroups
		
		foreach ($grp in $groups)  
		{
			## Increment $groupCount.
			$groupCount = $groupCount +1

			if ($grp.Name -like "*Develoeprs*")
			{
				## Increment $devCount.
				$devCount = $devCount +1
	
				Write-Output $site.AllWebs[$i] | Select Url;

				"    Group:    " + $grp.name; 
				foreach ($user in $grp.users) 
				{
					## Increment $userCount.
					$userCount = $userCount +1

					"         User:    " + $user.name
				} 
			}
		}

		$site.Dispose();
	}
}
"=========================================="
"Site Collections:   " + $siteCount
"Sub-Sites:          " + $webCount
"Groups:             " + $groupCount
"Developer Groups:   " + $devCount
"Users:              " + $userCount

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
Synchronize a new Active Directory domain with an existing Office 365 tenant
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question