Monday 9 June 2014

SharePoint 2013 Quota Template creation script

As SharePoint administrator I frequently have requests for for setting up new site collection quotas and associating site collection with them.
For me, the process for this task is very annoying when it is done via the UI in the Central administration.
The problem is that we do not have OOB PowerShell functions to do this. So I created a script that can create new quota templates and can associate it with one or more site collections.
You just need to give a Name of the new quota template (the script will check first if there is a quota whit this name) Max Level of storage. Optionally you can give a Warning Level, but if it is not specified the script will set 80% from the Max value.

The script is creating the quota via the Object Model and assignment of the quota is done with the Set-SPSite cmdlet.

function CreateQuotaTemplate ($qName, $qMaxLevelMB, $qWarnLevelMB)
    $quotaTemplate = New-Object Microsoft.SharePoint.Administration.SPQuotaTemplate
    $quotaTemplate.Name = $qName
    $quotaTemplate.StorageMaximumLevel = ($qMaxLevelMB * 1024)*1024
    $quotaTemplate.StorageWarningLevel = ($qWarnLevelMB * 1024)*1024
    $contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService

Below you can see how the new quota is created. It may not appear immediately in the Central Admin page, but you can see it by listing all quotas with flowing line:


As I said above. You can create a quota and directly apply it to one or many site collection.

Feel free to use and modify the script to best suit your needs. I am working with it on SharePoint 2013 on PowerShell 4.0

No comments:

Post a Comment