Get Site Quota Information For SharePoint Farm

Site Quota comes in handy when you wish to enforce the size limits in your SharePoint site collections. It lets you set the storage limit values and warning limit values, for better farm management.

The below script will bring forth the site quota and other related information, such as maximum storage limit, maximum storage warning, etc. for the entire farm. The output will be in CSV format.
  1. if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)   
  2. {  
  3.     Add-PSSnapin "Microsoft.SharePoint.PowerShell"  
  4. }  
  5.   
  6. $templates = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.quotatemplates  
  7. $tFound = $false  
  8. $templateName = "No template found"  
  9.   
  10. $results = @()  
  11.   
  12. $sites = Get-SPSite -Limit ALL  
  13. try   
  14. {  
  15.   foreach ($site in $sites)  
  16.   {  
  17.       foreach ($qt in $templates)  
  18.          {  
  19.             if ($qt.QuotaId -eq $site.Quota.QuotaID)  
  20.                 {  
  21.                    $templateName = $qt.Name;   
  22.                    $tFound = $true  
  23.                 }  
  24.             }  
  25.             if ($tFound -eq $false)  
  26.             {  
  27.                 $templateName = “No Template Applied”  
  28.             }   
  29.             $tFound=$false;                 
  30.   
  31.              $RowDetails = @{  
  32.                   "Site URL"                            = $site.Url  
  33.                   "Storage Used"                        = $site.Usage.Storage/1MB  
  34.                   "Storage Available Warning"           = $site.Quota.StorageWarningLevel/1MB  
  35.                   "Storage Available Maximum"           = $site.Quota.StorageMaximumLevel/1MB  
  36.                   "Sandboxed Resource Points Warning"   = $site.Quota.UserCodeWarningLevel  
  37.                   "Sandboxed Resource Points Maximum"   = $site.Quota.UserCodeMaximumLevel  
  38.                   "Quota Name"                          = $templateName  
  39.                 }  
  40.       $results += New-Object PSObject -Property $RowDetails  
  41.       $site.Dispose()   
  42.     }   
  43. }   
  44.       
  45. catch  
  46. {          
  47.    $e = $_.Exception  
  48.    $line = $_.InvocationInfo.ScriptLineNumber  
  49.    $msg = $e.Message   
  50.   
  51.    Write-Host -ForegroundColor Red "caught exception: $e at $line"  
  52.    Write-Host $msg  
  53.    write-host "Something went wrong"  
  54. }   
  55.   
  56. $results | Export-csv -Path C:\SiteQuotaDetailedInfo.csv -NoTypeInformation  
  57. Write-Host "-------------------- Completed! -----------------------------"  

And, here is a screenshot of the exported data in CSV (of course, with a little bit of styling in Excel).

Ebook Download
View all
Learn
View all