PoshCode Archive  Artifact [23f4c01639]

Artifact 23f4c01639308748dfc8bdcaecb849e7d02216f5176cc317b251e6adc6af47da:

  • File SharePoint-Site-Owners.ps1 — part of check-in [b4edb4d7bf] at 2018-06-10 13:39:42 on branch trunk — List all the members of the “AssociatedOwnerGroup” of each site (including root site) of each Site Collection of each Web Application in the farm. (user: Lucas Araujo size: 1960)

# encoding: ascii
# api: powershell
# title: SharePoint Site Owners
# description: List all the members of the “AssociatedOwnerGroup” of each site (including root site) of each Site Collection of each Web Application in the farm.
# version: 0.1
# author: Lucas Araujo
# license: CC0
# x-poshcode-id: 4347
# x-derived-from-id: 4348
# x-archived: 2015-05-16T08:54:08
# x-published: 2015-07-31T21:09:00
#
# Writes down the result to CSV files
#
Get-SPWebApplication | Get-SPSite -Limit ALL | 
ForEach-Object {
    $content = "";
    $rootSite = New-Object Microsoft.SharePoint.SPSite($_.Url)
    $subSites = $rootSite.AllWebs;
    
    if($subSites.Count -le 0)
    {
	@@ This occurs when a Site Collection does not contains any subsite (not even the root site)
        Write-Host "The Site Collection"  $siteUrl  "does not contains any site."
    }
    else
    {
        foreach($subsite in $subSites) 
        {
            $siteOwners = $subsite.AssociatedOwnerGroup
            if($siteOwners)
            {
                foreach ($owner in $subsite.Users) 
                {
                    if($subsite.ParentWeb)
                    {
                        $content += "$($subsite.ParentWeb.Url),$($owner.Name),Site Owner`n"
                    }
                    else
                    {
                        $content += "$($subsite.Url),$($owner.Name),Site Owner`n"
                    }
                }
            }
            else
            {
                $content += "Could not find an AssociatedGroupOwner in the site with the Url: $($subsite.Url) `n"
            }  
            
            $subsite.Dispose()
            $rootSite.Dispose()
        }
        @@ Set the patch to the CSV files
        $FilePath = "C:\Owners\" + $_.Url.Replace("http://","").Replace("/","-").Replace(":","-") + ".csv";
	out-file -filepath $FilePath -inputobject $content
    }
}