Get Web Sites Owners Listing (Powershell to Text File)

I created this script to gather a listing of web site owners within a Site Collection.  It has been set to only gather the first tier of sites.  If you wish to go deeper, change the comparision.

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
function IterateSubSites ([Microsoft.SPWeb]$subSite)
{
    if ($subSite -ne $null)
    {
        if($subSite.Webs -ne $null)
        {
            foreach($subsites in $subSite.Webs)
            {
                IterateSubSites($subsites)
            }
        }
    }
}
 
$webApplicationURL = "http://contoso.com"
$webApp = Get-SPWebApplication $webApplicationURL
 
foreach($site in $webApp.Sites)
{
    foreach($subWeb in $site.AllWebs)
    {
       if(($subWeb.Url.Split("/") | measure-object).Count -lt 5)
{
        $output += $subWeb.Url + "`r`n`r`n"
        foreach($group in $subWeb.Groups)
        {
            if($group.Name -like "*Owners*")
            {
                $output += "Owner(s): " + "`r`n`r`n"
                foreach($user in $group.Users)
                {$output += $user.Name + " - " + $user.Email + "`r`n`r`n"; }
            }
        }
}
    }
    if($subWeb.IsRootWeb -ne $true)
    {
        IterateSubSites($subWeb)
    }
    $subWeb.Dispose()
}
$site.Dispose()
$output | Out-File "C:\owners.txt" 
Posted in SharePoint 2010, SharePoint 2013.

Leave a Reply

Your email address will not be published. Required fields are marked *