You are requested to retrieve all users in all groups inside all site collections under a web application.
Solution:
Run this PowerShell script in SharePoint Management Shell
#Header "SiteCollectionURL;GroupName;PermissionLevel;UserName;UserID" Try { $WebApplicationUrl = "http://contoso.com" $webApplication = Get-SPWebApplication $WebApplicationUrl -ErrorAction SilentlyContinue; if($webApplication -ne $null) { foreach($site in $webApplication.Sites){ #Get all Site Collection Administrator foreach ($siteAdmin in $site.RootWeb.SiteAdministrators) { $site.URL+";Site Administrator;Full Control;"+$siteAdmin.DisplayName+";"+$siteAdmin.UserLogin } $groups = $site.RootWeb.SiteGroups foreach ($group in $groups) { foreach ($user in $group.users) { $site.URL+";"+$group.Name+";"+$group.Roles+";"+$user.DisplayName+";"+$user.UserLogin } } $site.Dispose() } } else { Write-Host "Could not find Web Application $WebApplicationUrl" -ForegroundColor Red; } } Catch [system.exception] { "Error Occurred: $_" }
Usually I will just simply save the code as in PS1 file and use this command to save it into CSV file.
file.ps1 > result.csv
And then use Excel to massage the data accordingly. Have fun!
For SP2007 solution, click here.