SharePoint 2013: Get Site information using PowerShell Script

I have uploaded a PowerShell Script on TechNet gallery, with that script you can get the site collection information which include Content DB details, count of current sub sites, and also size of each sub site, site collection and content DB. You can download and execute the script file using administrative rights on SharePoint Farm.

The output of file is saved in CSV format, which you can save it to any defined path.

The script contains 5 functions, the main function is GetGeneralInfo which generates all site information, it takes site URLS and output file path as parameter.

Function GetGeneralInfo($siteUrl, $OutputFile) 
{ 

#Write CSV- TAB Separated File) Header 
"Name `t Value" | out-file $OutputFile 

$ContentDB =  Get-SPContentDatabase -site $siteUrl 
$ContentDatabaseSize = [Math]::Round(($ContentDatabase.disksizerequired/1GB),2) 

"Database Name  `t $($ContentDB.Name)" | Out-File $OutputFile -Append 
"Database ID  `t $($ContentDB.ID)" | Out-File $OutputFile -Append 
"Site count `t $($ContentDB.CurrentSiteCount)" | Out-File $OutputFile -Append 
"Site count `t $($ContentDB.MaximumSiteCount)" | Out-File $OutputFile -Append 
"Can Migrate `t $($ContentDB.CanMigrate)" | Out-File $OutputFile -Append 
"Content DB Size `t $($ContentDatabaseSize) GB" | Out-File $OutputFile -Append 
"Database Servername `t $($ContentDB.Server)" | Out-File $OutputFile -Append 
"Connection String `t $($ContentDB.DatabaseConnectionString)" | Out-File $OutputFile -Append 
"Display Name `t $($ContentDB.DisplayName)" | Out-File $OutputFile -Append 
"Schema `t $($ContentDB.SchemaVersionXml)" | Out-File $OutputFile -Append 

GetWebSizes -StartWeb $siteUrl 
}

The function call is quite simple as below:

GetGeneralInfo "http://spFarm" "C:\GeneralInfo.csv"

The basic detail of the site collection is fetched from Get-SPContentDatabase class, and sub site and site collection size is fetched from remaining functions which is calculated all files in the document libraries.

If you feel any difficulty on running this script then do update me.

This script has been tested on SharePoint 2010 and SharePoint 2013

The following two tabs change content below.
Adnan Amin
Adnan is an active SharePoint MVP and having over 11 years of extensive experience with major expertise on SharePoint Server, office 365, .Net Platform and Microsoft BI, Adnan is currently working as SharePoint Architect at FMT Consultants. He is MCT Regional Lead for Pakistan Chapter since 2012. He is working on SharePoint for past seven years and worked on different intranet/intranet solutions for private & govt. sector majorly in United States and Gulf region, which include OOB and customized solutions. He is a trainer, technology evangelist and also speaks in community forums.

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *