
[SPS2013] Get Storage and Quota used using PowerShell
So, here goes:
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 |
if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) { Add-PSSnapin Microsoft.SharePoint.PowerShell } function Get-SPQuotaTemplate($spSite) { return $spSite.WebApplication.WebService.QuotaTemplates | ?{ $_.QuotaID -eq $spSite.Quota.QuotaID } } function Get-SPApplicableQuota($spSite) { [Microsoft.SharePoint.Administration.SPQuota] $spSiteQuota = $spSite.Quota if ($spSite.Quota.QuotaID -ne 0) { $spSiteQuotaTemplate = Get-SPQuotaTemplate $spSite if ($spSiteQuotaTemplate -ne $null) { $spSiteQuota = [Microsoft.SharePoint.Administration.SPQuota] $spSiteQuotaTemplate } } return $spSiteQuota } function Get-SPQuotaInfo() { $quotaIDColumn = @{name = 'QuotaID'; expression = { $_.Quota.QuotaID } } $quotaTemplateColumn = @{name = 'QuotaTemplate'; expression = { $quotaID = $_.Quota.QuotaID; if ($quotaID -eq 0) { "No Template" } else { ((Get-SPQuotaTemplate $_).Name, "Unknown ($($quotaID))" -ne $null)[0] } } } $storageMaximumLevelColumn = @{ name = 'StorageMaximumLevel'; expression = { (Get-SPApplicableQuota $_).StorageMaximumLevel } } $storageWarningLevelColumn = @{ name = 'StorageWarningLevel'; expression = { (Get-SPApplicableQuota $_).StorageWarningLevel } } $storageUsedColumn = @{ name = 'StorageUsed'; expression = { $_.Usage.Storage } } $spQuotaInfo = $null # Sites must be retrieved with elevated privileges in order to ensure consistent access to the usage data. [Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges({ [Microsoft.SharePoint.SPSite[]] $spSites = Get-SPSite -Limit ALL $spQuotaInfo = $spSites | Select Url, $quotaIDColumn, $quotaTemplateColumn, $storageMaximumLevelColumn, $StorageWarningLevelColumn, $storageUsedColumn # Passes the array of PSCustomObjects generated by the Select back out to the parent. Set-Variable -Scope 1 -Name spQuotaInfo -Value $spQuotaInfo }) return $spQuotaInfo } function Format-QuotaInfoTable($spQuotaInfo) { $quotaTemplateDisplay = @{name = 'Quota Template'; expression = { $_.QuotaTemplate } } $storageMaximumLevelDisplay = @{ name = 'Storage Maximum Level'; expression = { if ($_.StorageMaximumLevel -eq 0) { "No Limit" } else { "{0:N0} MB" -f ($_.StorageMaximumLevel / 1048576.0) } }; align = 'right' } $storageWarningLevelDisplay = @{ name = 'Storage Warning Level'; expression = { if ($_.StorageWarningLevel -eq 0) { "No Limit" } else { "{0:N0} MB" -f ($_.StorageWarningLevel / 1048576.0) } }; align = 'right' } $storageUsedDisplay = @{ name = 'Storage Used'; expression = { $_.StorageUsed / 1048576.0 }; align = 'right'; formatString = '{0:N3} MB' } $percentQuotaUsedDisplay = @{ name = 'Quota Used'; expression = { if ($_.StorageMaximumLevel -eq 0) { 0 } else { $_.StorageUsed / $_.StorageMaximumLevel } }; formatString = '{0:P}' } $spQuotaInfo | ft -AutoSize Url, $quotaTemplateDisplay, $storageMaximumLevelDisplay, $storageWarningLevelDisplay, $storageUsedDisplay, $percentQuotaUsedDisplay } $spQuotaInfo = Get-SPQuotaInfo | Sort StorageUsed -Descending Format-QuotaInfoTable $spQuotaInfo |
The results will look similar to the ones below: