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