Scenario: You want a list of all the sites quota on your SharePoint environment.
Solution: use the following PowerShell script (you might want to save it as “quota.ps1″ and run it from the SharePoint 2010 Management Shell
$t = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.quotatemplates
$tFound = $false
$webApp = Get-SPWebApplication | %{$_.Sites} | Get-SPSite -Limit ALL
$webApp | fl Url, @{n=”Storage Used/1MB”;e={[int]($_.Usage.Storage/1MB)}},
@{n=”Storage Available Warning/1MB”; e={[int](($_.Quota).StorageWarningLevel/1MB)}},
@{n=”Storage Available Maximum/1MB”; e={[int](($_.Quota).StorageMaximumLevel/1MB)}},
@{n=”Sandboxed Resource Points Warning”;e={[int](($_.Quota).UserCodeWarningLevel)}},
@{n=”Sandboxed Resource Points Maximum”;e={[int](($_.Quota).UserCodeMaximumLevel)}},
@{n=”Quota Name”; e={ foreach($qt in $t){if($qt.QuotaId -eq [int](($_.Quota).QuotaID)){$qt.Name; $tFound = $true}} if($tFound -eq $false){“No Template Applied”}$tFound=$false;}} >> c:\quotaoutput.txt
if($parent) {$webApp.Dispose(); $t.Dispose()}
The results will look like:
Url : http://sps2010:3033
Storage Used/1MB : 12
Storage Available Warning/1MB : 0
Storage Available Maximum/1MB : 0 Sandboxed Resource Points Warning : 100
Sandboxed Resource Points Maximum : 300
Quota Name : No Template Applied
Update from June 23 2018
Since some people from Capgemini consider that my script “might work” and think it is “terrible” and “not human readable”, I thought to ease their pain and re-write it in a more “non-geeky” way:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
#Load SharePoint PowerShell if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -EA SilentlyContinue) -eq $null) { Write-Host "Loading the SharePoint PowerShell snapin..." Add-PSSnapin Microsoft.SharePoint.PowerShell } Function Get-SiteInfoQuota () { $templates = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.quotatemplates $tFound = $false Get-SPSite -Limit ALL| Select Url, @{n="Storage Used/1MB";e={[int]($_.Usage.Storage/1MB)}}, @{n="Storage Available Warning/1MB"; e={[int](($_.Quota).StorageWarningLevel/1MB)}}, @{n="Storage Available Maximum/1MB"; e={[int](($_.Quota).StorageMaximumLevel/1MB)}}, @{n="Sandboxed Resource Points Warning";e={[int](($_.Quota).UserCodeWarningLevel)}}, @{n="Sandboxed Resource Points Maximum";e={[int](($_.Quota).UserCodeMaximumLevel)}}, @{n="Quota Name"; e={ foreach($qt in $templates) { if($qt.QuotaId -eq [int](($_.Quota).QuotaID)) { $qt.Name; $tFound = $true } } if($tFound -eq $false) { "No Template Applied" } $tFound=$false; } } } # User Decides if the info is displayed on screen or saved to a file $opt = Read-Host "Do you want the information displayed on screen or saved to file (press S for screen or F for File)" switch ($opt) { #If S is chosen S { Get-SiteInfoQuota } # If F is chosen F { $savepath=Read-Host "Please enter the path where the logs should be saved" #Checking if path exists, if not create it if (!(Test-Path -Path $savepath)) { New-Item $savepath -ItemType Directory Write-Host "Creating folder $savepath" } #Saving file $date=get-date -Format M.d.yyyy $fullpath=$savepath+"\"+$date+"-QuotaInfo.csv" Get-SiteInfoQuota | Export-Csv $fullpath Write-Host "Data Saved to: "$fullpath } } |
