Tuesday, October 1, 2013

PowerShell script to Monitor and Auto-expand SharePoint site collection quota

Get-SPSite -Limit ALL | 
    Where { $_.Url -like "*/teamsite/*" -and [int]($_.Usage.Storage/1MB) -gt [int](($_.Quota).StorageWarningLevel/1MB) } |
    ForEach-Object {
 $maxSize = ($_.Quota).StorageMaximumLevel + (5000*1MB)
 $maxWarning = $maxSize - (200*1MB)
        Set-SPSite -Identity $_.Url -MaxSize $maxSize -WarningSize $maxWarning
    }

This script will retrieve all Sharepoint site objects where there is a "/teamsite/" found in the URL, and where the current usage has exceeded the user warning level.
It will automatically increment 5 GB of storage quota and update the warning level as well.

However, there are situations where some sites have unlimited quota. In this case, you will have to modify the script slightly to include an additional condition:
Where { $_.Url -like "*/teamsite/*" -and [int](($_.Quota).StorageWarningLevel/1MB) -gt 0 -and [int]($_.Usage.Storage/1MB) -gt [int](($_.Quota).StorageWarningLevel/1MB) }
Related Posts Plugin for WordPress, Blogger...