PoshCode Archive  Artifact Content

Artifact 16202e3d0e35e1ab49208c8a14a8b4ba23f6e6d28a3c8cf647b3432899abedab:

  • File SharePoint-Site-Owners.ps1 — part of check-in [e24568ce44] at 2018-06-10 13:19:22 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: 1933)

# 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: 3044
# x-archived: 2015-10-08T04:29:10
# x-published: 2012-11-10T06:05: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
    }
}