When working with clients on their SharePoint deployment I often get questions about the quota templates and how they work. Quotas are kind of odd because of the disconnected nature of the quota template and the quota that is assigned to a site collection. Often people assume that changing the template settings affects all site collections using that template. Unfortunately that is not the case. The issue is made worse by the fact that the “Site Collection Quotas and Locks” page within Central Admin shows the values of the template assigned and not the actual quota assigned to the site – so administrators will change the template settings, then look at a site collection using that template and it “appears” to them that the template change has affected the site. But if you go to the command line and run the “enumsites” command you can see that the quota values have not in fact been changed.
So how do you get the value applied? Simply click the “OK” button on the “Site Collection Quotas and Locks” page. Okay, so that’s all nice and peachy if you have one or two site collections, but what if you have several hundred? That’s where my new command comes in: gl-syncquotas. Synchronizing quotas using the object model is actually pretty easy – you just get an instance of the quota template (SPQuotaTemplate), which inherits from SPQuota, and set the Quota property of the SPSite object – that’s it.
Here’s the code showing how I did it:
The help for the command is shown below:
C:\>stsadm -help gl-syncquotas stsadm -o gl-syncquotas Synchronizes site quota settings with those defined in the quota templates. Parameters: [-scope <Farm | WebApplication | Site (default)>] [-url <url>] [-quota <quota template name to synchronize (sites using other quotas will not be affected)>] [-setquota (if scope is site or web application and a quota is specified apply the quota to any site that does not currently have a quota assigned)]
The following table summarizes the command and its various parameters:
|Command Name||Availability||Build Date|
|gl-syncquotas||WSS v3, MOSS 2007||Released: 2/12/2009
|Parameter Name||Short Form||Required||Description||Example Usage|
|url||Yes if scope is not Farm||URL of the web application or site collection.||-url http://mysites|
|scope||s||No – defaults to site||The scope to use. Valid values are “Farm”, “WebApplication”, and “Site”||-scope site
|quota||q||No||The name of the quota template to synchronize. If not specified then all site collections will be synchronized regardless of the quota assigned to the site.||-quota "Personal Site"
-q "Personal Site"
|setquota||set||No||If the scope is site or webapplication and a site collection has no quota assigned to it then the quota template specified via the –quota parameter will be assigned to the site.||-setquota
The following is an example of how to synchronize all the “My Site” sites and assign the “Personal Site” quota template to any site collections under the http://mysites web application that do not currently have a quota assigned:
stsadm -o gl-syncquotas -scope webapplication -url http://mysites -quota "Personal Site" -setquota
The following is a list of quota related commands that I have created and are available for download from this site.
Creating a quota template can be done using the central administration tool by going to “Central Administration > Application Management > Quota Templates”. This command will create a quota template in the same way as is done via the central administration tool.
C:\>stsadm -help gl-createquotatemplate stsadm -o gl-createquotatemplate Creates a new quota template Parameters: -name <quota> [-storagemaxlevel <maximum>] [-storagewarninglevel <warning>]
Here’s an example of how to create a template:
Once the template is created you can assign it to a site using STSADM’s setproperty command:
stsadm –o gl-createquotatemplate –name “My Sites” –storagemaxlevel 50 -storagewarninglevel 40
stsadm –o setproperty –propertyname defaultquotatemplate –propertyvalue “My Sites” –url “http://mysites/”
The main code that handles the creation of the quota template can be seen below.
The code is essentially just grabbing an SPWebService class which returns the SPQuotaTemplateCollection. We then use that collection to add new items to the collection - the same is true for editing but instead of adding a new item we are retrieving and modifying an existing item.
Editing a quota template can be done using the central administration tool by going to “Central Administration > Application Management > Quota Templates”. This command will edit a quota template in the same way as is done via the central administration tool.
C:\>stsadm -help gl-editquotatemplate stsadm -o gl-editquotatemplate Edits an existing quota template Parameters: -name <quota name> [-storagemaxlevel <maximum storage level in megabytes - set to zero to clear>] [-storagewarninglevel <warning level in megabytes - set to zero to clear>]
Here’s an example of how to edit a template:
stsadm –o gl-editquotatemplate –name “My Sites” –storagemaxlevel 50 -storagewarninglevel 40