Solved

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

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

838 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