Script to find sharepoint group members across sites


The below is a script to look forĀ a group and group members across sites in the SharePoint farm.

You can customize it for site collection and web apps along with export columns.

$sites = Get-SPWebApplication P_Teams" | Get-SPSite -limit all
"Site Collection`t Group`t User Name`t User Login" | out-file groupmembersreport.csv
foreach($site in $sites)
{
	$webs = $site.allwebs
    foreach($web in $webs)
   {
    if($web.hasuniqueroleassignments)
    {
    $group = $web.Groups |?{$_.Name -like "*power*"}
    # you can also filter by exact group name { $_.Name -eq "Power Users"} or look for word in a group
	foreach($user in $group.Users)
		{	
		"$($web.url) `t $($group.Name) `t $($user.displayname) `t $($user) " | out-file groupmembersreport.csv -append
		}
    }
  }
$site.Dispose()

}