Solved

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

Posted on 2011-02-18
2
809 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
A brief introduction to what I consider to be the best editor for PowerShell.
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now