Solved

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

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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article will help you understand what HashTables are and how to use them in PowerShell.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

747 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

10 Experts available now in Live!

Get 1:1 Help Now