Site Quota
A quota specifies the storage limit values for the maximum amount of data that can be stored in a site collection. Quotas also specify the storage size that, when reached, triggers an e-mail alert to the site collection administrator. Quotas can be saved as quota templates that can then be applied to any site collection in a SharePoint Farm. Using quota templates rather than individual quotas can simplify setting storage limits on new site collections.
The storage limit applies to the site collection as a whole. In other words, the storage limit applies to the total size of the content for the top-level site and for all subsites within the site collection. If versioning is enabled, the versions in a site and the content in the Recycle Bins count toward storage limits. You can also specify a percentage of storage limits for the second-stage Recycle Bin.
The script collects the following information:
- Site URL
- Site owner email
- Site last modified date
- Maximum storage
- Used storage
- Site quota used
Sites under specific web appThe following piece of code gets the quota details for all the sites under a specific webapplication:
- $Siteurl = read - host "Enter any site collection URL under the specific web application "
-
- $TestSiteCollectionExists = get - spsite $Siteurl
-
- if ($TestSiteCollectionExists - ne $null)
-
- {
-
- $Rootweb = New - Object Microsoft.Sharepoint.Spsite($Siteurl);
-
- $Webapp = $Rootweb.Webapplication;
-
- #Loops through each site collection within the Web app,
- if the owner has an e - mail address this is written to the output file
-
- Foreach($Site in $Webapp.Sites)
-
- {
-
- if
-
- ($Site.Quota.Storagemaximumlevel - gt0)
-
- {
- [int] $MaxStorage = $Site.Quota.StorageMaximumLevel / 1MB
- }
- else
- {
- $MaxStorage = "0"
- };
- if
- ($Site.Usage.Storage - gt0)
{
- [int] $StorageUsed = $Site.Usage.Storage / 1MB
- };
- if
- ($Storageused - gt0 - and $Maxstorage - gt0)
- {
- [int] $SiteQuotaUsed = $Storageused / $Maxstorage * 100
- }
else
- {
- $SiteQuotaUsed = "0"
- };
- $Web = $Site.Rootweb;
- $Site.Url + "," + $Site.Owner.Email + "," + $Web.LastItemModifiedDate.ToShortDateString() + "," + $MaxStorage + "," + $StorageUsed + "," + $SiteQuotaUsed | Out - File - Encoding Default - Append - FilePath $Output;
- $Web.Dispose();
- $Site.Dispose()
- }
- write - host "The output is available in "
- $Output " location" - fore yellow
- }
else
- {
- write - host "Invalid site collection URL.... Please check the URL" - fore cyan
- }
Sites under SharePoint FarmThe following piece of code gets the quota details for all the site collections under the SharePoint Farm:
- $SiteCollections = get - spsite
- Foreach($Site in $SiteCollections)
- {
- if
- ($Site.Quota.Storagemaximumlevel - gt0)
- {
- [int] $MaxStorage = $Site.Quota.StorageMaximumLevel / 1MB
- }
- else
- {
- $MaxStorage = "0"
- };
- if
- ($Site.Usage.Storage - gt0)
- {
- [int] $StorageUsed = $Site.Usage.Storage / 1MB
- };
- if
- ($Storageused - gt0 - and $Maxstorage - gt0)
- {
- [int] $SiteQuotaUsed = $Storageused / $Maxstorage * 100
- }
- else
- {
- $SiteQuotaUsed = "0"
- };
- $Web = $Site.Rootweb;
- $Site.Url + "," + $Site.Owner.Email + "," + $Web.LastItemModifiedDate.ToShortDateString() + "," + $MaxStorage + "," + $StorageUsed + "," + $SiteQuotaUsed | Out - File - Encoding Default - Append - FilePath $Output;
- $Web.Dispose();
- $Site.Dispose()
- }
- write-host "The output is available in " $Output " location" -fore yellow
Complete code
- $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
- $LogFile = ".\SiteCollectionQuotaDetailsPatch-$LogTime.rtf"
- start-transcript $logfile
# Add SharePoint PowerShell Snaping
- if( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
- {
- Add-PSSnapin Microsoft.SharePoint.Powershell
-
- $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
- Set-Location $scriptBase
- $Output = $scriptBase + "\" + "SiteQuotaDetails.csv";
- "Site URL" + "," + "Owner Email" + "," + "Root Site Last Modified" + "," + "Quota Limit (MB)" + "," + "Total Storage Used (MB)" + "," + "Site
- Quota Percentage Used" | Out-File -Encoding Default -FilePath $Output;
- write-host "#############################################################" -fore cyan
- write-host "Enter Option 1 to get the quota details for the site collections under specific web application" -fore green
- write-host "Enter Option 2 to get the quota details for all the site collection in the sharepoint farm" -fore green
- write-host "#############################################################" -fore cyan
#Switch case
1
- {
- $Siteurl = read - host "Enter any site collection URL under the specific web application "
- $TestSiteCollectionExists = get - spsite $Siteurl
- if ($TestSiteCollectionExists - ne $null)
- {
- $Rootweb = New - Object Microsoft.Sharepoint.Spsite($Siteurl);
- $Webapp = $Rootweb.Webapplication;
- #Loops through each site collection within the Web app,
- if the owner has an e - mail address this is written to the output file
- Foreach($Site in $Webapp.Sites)
- {
- if
- ($Site.Quota.Storagemaximumlevel - gt0)
- {
- [int] $MaxStorage = $Site.Quota.StorageMaximumLevel / 1MB
- }
- else
- {
- $MaxStorage = "0"
- };
- if
- ($Site.Usage.Storage - gt0)
- {
- [int] $StorageUsed = $Site.Usage.Storage / 1MB
- };
- if
- ($Storageused - gt0 - and $Maxstorage - gt0)
- {
- [int] $SiteQuotaUsed = $Storageused / $Maxstorage * 100
- }
- else
- {
- $SiteQuotaUsed = "0"
- };
- $Web = $Site.Rootweb;
- $Site.Url + "," + $Site.Owner.Email + "," + $Web.LastItemModifiedDate.ToShortDateString() + "," + $MaxStorage + "," + $StorageUsed + "," + $SiteQuotaUsed | Out - File - Encoding Default - Append - FilePath $Output;
- $Web.Dispose();
- $Site.Dispose()
- }
- write - host "The output is available in "
- $Output " location" - fore yellow
- }
- else
- {
- write - host "Invalid site collection URL.... Please check the URL" - fore cyan
- }
-
- }
2
- {
- $SiteCollections = get - spsite
-
- Foreach($Site in $SiteCollections)
-
- {
- if
- ($Site.Quota.Storagemaximumlevel - gt0)
- {
- [int] $MaxStorage = $Site.Quota.StorageMaximumLevel / 1MB
- }
- else
- {
- $MaxStorage = "0"
- };
- if
- ($Site.Usage.Storage - gt0)
{
- [int] $StorageUsed = $Site.Usage.Storage / 1MB
- };
- if
- ($Storageused - gt0 - and $Maxstorage - gt0)
- {
- [int] $SiteQuotaUsed = $Storageused / $Maxstorage * 100
- }
- else
- {
- $SiteQuotaUsed = "0"
- };
- $Web = $Site.Rootweb;
- $Site.Url + "," + $Site.Owner.Email + "," + $Web.LastItemModifiedDate.ToShortDateString() + "," + $MaxStorage + "," + $StorageUsed + "," + $SiteQuotaUsed | Out - File - Encoding Default - Append - FilePath $Output;
- $Web.Dispose();
- $Site.Dispose()
- }
- write - host "The output is available in "
- $Output " location" - fore yellow
- }
-
- }
- stop-transcript
Execution Procedure
- Step 1: Download and copy the script to the SharePoint server
- Step 2: Navigate to the script path
- Step 3: Execute the script
Enter option “1” or “2” to get the desired output.
ConclusionThus this article outlines how to get the site quota details for SharePoint sites using a PowerShell script.