How To: Get a list of site owners for all SharePoint sites

Here is something you may need to verify your users have the access they require: a PowerShell script which will run through all of the site collections and webs and display the list of site owners (people who belong to a Owner group).

Something like this:

Basically you save the code below as a ps1 script and run it in Management Shell.
If the output is too long, pipe it to file by using >> c:\output.txt in the command line calling the script.


function IterateSubSites ([Microsoft.SPWeb]$subSite) { if ($subSite $null) { if($subSite.Webs -ne $null)
{
foreach($subsites in $subSite.Webs)
{
IterateSubSites($subsites)
}
}
}
}

$webApplicationURL = "http://localhost"
$webApp = Get-SPWebApplication $webApplicationURL

foreach($site in $webApp.Sites)
{
foreach($subWeb in $site.AllWebs)
{
Write-Host $subWeb.Url
foreach($group in $subWeb.Groups) if($group.Name -like "*Owners*")
{
Write-Host "Owner(s): "
foreach($user in $group.Users)
{Write-Host $user.Name "; "; }
}
}
if($subWeb.IsRootWeb -ne $true)
{
IterateSubSites($subWeb)
}
$subWeb.Dispose()
}
$site.Dispose()
}

If stuff like this is something you do on a daily basis, you may like my .

Enjoy!

About the author: Yaroslav Pentsarskyy