In this article, I would like to share the steps to get a site collection details in the farm. This solution can be applied for SharePoint 2010, 2013 and SharePoint 2016.

If we are going to Google it, we will see many results which will giveus exact details in one script. In case we have the multi-farm or single SharePoint server farm, and the requirement is to get site collection details with the below information, we need to collect the web application's and site collection's details from the farm, like Web Application name, URL, Site collection Name, URL, Content DB, Size of Content DB, Created Date, Site owner and others in CSV format.

Below is the script which will perform this activity for us:

  1. If ((Get-PSSnapin | where {$_.Name -match "SharePoint.PowerShell"}) -eq $null)
  2. {
  3. Add-PSSnapin Microsoft.SharePoint.PowerShell
  4. }
  5. Clear-Host
  6. $ServerName = HostName #Bring your Server Name
  7. $webapps = Get-SPWebApplication
  8. $Output = "C:\$ServerName.csv" #Output file
  9. $SiteDataCollection = @() # Array to store data
  10. foreach ($webapp in $webapps){
  11. $webappurl = $webapp.URL;
  12. $webappname=$webapp.DisplayName
  13. $sites=get-spsite -limit all -WebApplication $webapp.URL
  14. foreach ($site in $sites)
  15. {
  16. $ContentDB = Get-SPContentDatabase -site $site.url
  17. $SiteData = New-Object PSObject
  18. $SiteData | Add-Member -type NoteProperty -name "Web Application URL" -value $webappurl
  19. $SiteData | Add-Member -type NoteProperty -name "Web Application Name" -value $webappname
  20. $SiteData | Add-Member -type NoteProperty -name "Site URL" -value $site.url
  21. $SiteData | Add-Member -type NoteProperty -name "Database Name" -value $ContentDB.Name
  22. $SiteData | Add-Member -type NoteProperty -name "Database Size" -value $($ContentDB.DiskSizeRequired /1024/1024)
  23. $SiteData | Add-Member -type NoteProperty -name "Date Created" -value $site.RootWeb.Created
  24. $SiteData | Add-Member -type NoteProperty -name "OWner" -value $site.Owner
  25. $SiteDataCollection += $SiteData
  26. }
  27. }
  28. $SiteDataCollection | Export-Csv -Path $Output -Force
  29. Write-Host "Successfully Completed" -ForegroundColor DarkRed

Copy the above script in PowerShell ISE of any SharePoint Server in the farm and click on Start.

You will be getting the result on the defined path with the server name.