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:
- If ((Get-PSSnapin | where {$_.Name -match "SharePoint.PowerShell"}) -eq $null)
- {
- Add-PSSnapin Microsoft.SharePoint.PowerShell
- }
- Clear-Host
-
-
- $ServerName = HostName #Bring your Server Name
- $webapps = Get-SPWebApplication
- $Output = "C:\$ServerName.csv" #Output file
-
-
- $SiteDataCollection = @() # Array to store data
- foreach ($webapp in $webapps){
-
- $webappurl = $webapp.URL;
- $webappname=$webapp.DisplayName
- $sites=get-spsite -limit all -WebApplication $webapp.URL
-
- foreach ($site in $sites)
- {
- $ContentDB = Get-SPContentDatabase -site $site.url
-
- $SiteData = New-Object PSObject
- $SiteData | Add-Member -type NoteProperty -name "Web Application URL" -value $webappurl
- $SiteData | Add-Member -type NoteProperty -name "Web Application Name" -value $webappname
- $SiteData | Add-Member -type NoteProperty -name "Site URL" -value $site.url
- $SiteData | Add-Member -type NoteProperty -name "Database Name" -value $ContentDB.Name
- $SiteData | Add-Member -type NoteProperty -name "Database Size" -value $($ContentDB.DiskSizeRequired /1024/1024)
- $SiteData | Add-Member -type NoteProperty -name "Date Created" -value $site.RootWeb.Created
- $SiteData | Add-Member -type NoteProperty -name "OWner" -value $site.Owner
-
- $SiteDataCollection += $SiteData
-
- }
-
- }
-
- $SiteDataCollection | Export-Csv -Path $Output -Force
-
- 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.