The following is a list of quota related commands that I have created and are available for download from this site.
gl-createquotatemplate
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:
stsadm –o gl-createquotatemplate –name "My Sites" –storagemaxlevel 50 -storagewarninglevel 40
Once the template is created you can assign it to a site using STSADM’s setproperty command:
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.
1SPFarm farm = SPFarm.Local;
2SPWebService webService = farm.Services.GetValue("");
3
4SPQuotaTemplateCollection quotaColl = webService.QuotaTemplates;
5
6if (quotaColl[name] != null)
7{
8 output = "The template specified already exists.";
9 return 0;
10}
11SPQuotaTemplate newTemplate = new SPQuotaTemplate();
12
13newTemplate.Name = name;
14newTemplate.StorageMaximumLevel = storagemaxlevel;
15newTemplate.StorageWarningLevel = storagewarninglevel;
16
17quotaColl.Add(newTemplate);
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.
gl-editquotatemplate
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