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.
- if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
- {
- Add-PSSnapin "Microsoft.SharePoint.PowerShell"
- }
-
- $templates = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.quotatemplates
- $tFound = $false
- $templateName = "No template found"
-
- $results = @()
-
- $sites = Get-SPSite -Limit ALL
- try
- {
- foreach ($site in $sites)
- {
- foreach ($qt in $templates)
- {
- if ($qt.QuotaId -eq $site.Quota.QuotaID)
- {
- $templateName = $qt.Name;
- $tFound = $true
- }
- }
- if ($tFound -eq $false)
- {
- $templateName = “No Template Applied”
- }
- $tFound=$false;
-
- $RowDetails = @{
- "Site URL" = $site.Url
- "Storage Used" = $site.Usage.Storage/1MB
- "Storage Available Warning" = $site.Quota.StorageWarningLevel/1MB
- "Storage Available Maximum" = $site.Quota.StorageMaximumLevel/1MB
- "Sandboxed Resource Points Warning" = $site.Quota.UserCodeWarningLevel
- "Sandboxed Resource Points Maximum" = $site.Quota.UserCodeMaximumLevel
- "Quota Name" = $templateName
- }
- $results += New-Object PSObject -Property $RowDetails
- $site.Dispose()
- }
- }
-
- catch
- {
- $e = $_.Exception
- $line = $_.InvocationInfo.ScriptLineNumber
- $msg = $e.Message
-
- Write-Host -ForegroundColor Red "caught exception: $e at $line"
- Write-Host $msg
- write-host "Something went wrong"
- }
-
- $results | Export-csv -Path C:\SiteQuotaDetailedInfo.csv -NoTypeInformation
- Write-Host "-------------------- Completed! -----------------------------"
And, here is a screenshot of the exported data in CSV (of course, with a little bit of styling in Excel).