Thursday, 24 March 2016

Get Site Collection Storage Information using Powershell

In this post, I am going to write powershell script to get storage data (Total Size, Storage Quota and Warning Size) of all site collections in a SharePoint farm. We can use the powershell cmdlet Get-SPSite to get site usage and quota details.


Get Storage Info for a given Site Collection

The below command gets the size and storage quota details of a given site collection. The Get-SPSite cmdlet returns the property Usage and includes the property Storage, this is the storage size of the site collection. The get Get-SPSite also returns the property Quota and it includes the properties StorageMaximumLevel and StorageWarningLevel.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$sc = Get-SPSite http://sp01:85
All these three values are in bytes, we need to manually convert the bytes value into MB or GB for friendly usage.
$sc = Get-SPSite http://sp01:85
$SizeinMB = [System.Math]::Round((($sc.Usage.Storage)/1MB),2) 
$MaxSizeInMB = [System.Math]::Round((($sc.Quota.StorageMaximumLevel)/1MB),2)
$WarningSizeInMB = [System.Math]::Round((($sc.Quota.StorageWarningLevel)/1MB),2)

Get Storage Info of all Site Collections

You can use the following powershell command to get the current size, storage quota and storage warning size details for all the site collections in SharePoint farm. The results are sorted by the site collection's total size in descending order.
Get-SPSite | Select-Object Url,  @{n="SizeInMB";e={(($_.Usage).Storage)/1MB}},
@{n="MaxSizeInMB";e={(($_.Quota).StorageMaximumLevel)/1MB }},
@{n="WarningSizeInMB";e={(($_.Quota).StorageWarningLevel)/1MB }} | 
Sort-Object -Descending -Property "SizeInMB" | FT
You can also export the output into csv file by using the powershell cmdlet Export-CSV.
Get-SPSite | Select-Object Url,  @{n="SizeInMB";e={(($_.Usage).Storage)/1MB}},
@{n="MaxSizeInMB";e={(($_.Quota).StorageMaximumLevel)/1MB }},
@{n="WarningSizeInMB";e={(($_.Quota).StorageWarningLevel)/1MB }} | 
Sort-Object -Descending -Property "SizeInMB" |
Export-CSV "C:\\site-collection-storage-info.csv" -NoTypeInformation -Encoding UTF8

Get Storage data of all Sites in a Web Application

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


No comments:

Post a Comment