Thursday, 17 March 2016

Get size of all Site Collections using Powershell

In this article, I am going to write Powershell script to get size of all site collections in SharePoint farm and find site collection size in a given web application. We can use the powershell cmdlet Get-SPSite to get site usage detail. The below command gets the size of a given site collection.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$sc = Get-SPSite http://sp01:85
$SizeinMB = [System.Math]::Round((($sc.Usage.Storage)/1MB),2) 
$SizeInGB = [System.Math]::Round((($sc.Usage.Storage)/1GB),2)

Find size of all site collections in SharePoint Farm

The following powershell command find and retrieves the size of all the site collections in SharePoint Farm. This command gets the storage usage in MB instead of bytes and sorted the site collections by size.
Get-SPSite | Select-Object Url, @{n="Database";e={$_.ContentDatabase.Name}},
@{n="SizeInMB";e={$_.Usage.storage/1MB}} | Sort-Object -Descending -Property "SizeInMB"
You can also export the site collection url, database and size details to csv file by using the powershell cmdlet Export-CSV.
Get-SPSite | Select-Object Url, @{n="Database";e={$_.ContentDatabase.Name}},
@{n="SizeInMB";e={$_.Usage.storage/1MB}} | Sort-Object -Descending -Property "SizeInMB" |
Export-CSV "C:\\site-collections-size.csv" -NoTypeInformation -Encoding UTF8

Get size of all site collections in a Web Application

The below powershell command retrieves all the site collections in a given webapplication and get the size of each site collection.
$CustomResult=@() 
$webAppUrl ="http://sp01/"
$SiteCollections =  Get-SPSite -WebApplication $webAppUrl -Limit All # get all site collections
$SiteCollections | ForEach-Object { 
 
     $CustomResult += [PSCustomObject] @{ 
     SiteColUrl = $_.Url 
     Database = $_.ContentDatabase.Name
     SizeinMB = [System.Math]::Round((($_.Usage.Storage)/1MB),2) 
     SizeInGB = [System.Math]::Round((($_.Usage.Storage)/1GB),2)
     }           
}
$CustomResult | Select SiteColUrl,Database,SizeinMB,SizeInGB

Advertisements
Advertisements

No comments:

Post a Comment