Get Site Collection Administrators



For one activity I had to find all Site Collection Administrators for each and every web application. since I had only few web applications. I managed get it done with the help of bellow link.

 https://sharepoint.stackexchange.com/questions/209841/get-site-collection-administrators-using-powershell

after few modifications, now this script will generate a .csv file with site name and all site collection administrators for each site collection.

Add-PSSnapin Microsoft.SharePoint.PowerShell
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null

$webApp = Get-SPWebApplication -Identity "http://webappURL"

$logFilePath = "FilePath\$($webApp.Name)-Log.log";

Add-Content -Path $logFilePath -value "SiteName | Admin Name";

$siteCollections = $webApp.Sites ;

foreach($spSite in $siteCollections)
{

  $siteURL$spSite.Url;

  $siteCollectionAdmins = $spSite.RootWeb.SiteAdministrators;

    foreach ($admin in $siteCollectionAdmins)
    {

      Write-Host $spSite.Url "|" $admin.DisplayName;
      Add-Content -Path $logFilePath -value " $($siteURL) | $($admin.DisplayName)";

    }

  $spSite.Dispose();

}


Hope This will help someone.

Cheers

Popular posts from this blog

How to Create Host Header to SharePoint Web Application

System.Data.SqlClient.SqlException (0x80131904): The EXECUTE permission - User Profile Issue

How to add PDF Icon in SharePoint