Quota Templates

Posted on Posted in SharePoint 2007, STSADM Commands

The following is a list of quota related commands that I have created and are available for download from this site.

1. 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.

   1: SPFarm farm = SPFarm.Local;
   2: SPWebService webService = farm.Services.GetValue("");
   3:  
   4: SPQuotaTemplateCollection quotaColl = webService.QuotaTemplates;
   5:  
   6: if (quotaColl[name] != null)
   7: {
   8:  output = "The template specified already exists.";
   9:  return 0;
  10: }
  11: SPQuotaTemplate newTemplate = new SPQuotaTemplate();
  12:  
  13: newTemplate.Name = name;
  14: newTemplate.StorageMaximumLevel = storagemaxlevel;
  15: newTemplate.StorageWarningLevel = storagewarninglevel;
  16:  
  17: quotaColl.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.

2. 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

5 thoughts on “Quota Templates

  1. Unfortunately the quotas are set at the site collection level – I haven’t seen a way to do this at the web or user level though I imagine it would be possible to create a new Feature that would accomodate this.

  2. If you don’t already have a quota template assigned then my sync quota templates command will work for you. If you want to change the quota to a different template then you should use PowerShell.

  3. Gary,

    Do you know of a way, out-of-the-box, to set an expiration policy using quota templates for a site collection? The expiration policy would then automatically email the owner of the site collection after 1 year?

    Thanks,
    Joe

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA

*