Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-02-18
2
Medium Priority
?
838 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 2000 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

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Question has a verified solution.

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

The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

971 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