MOSS MVP

I've moved my blog to http://blog.falchionconsulting.com!. Please update your links. This blog is no longer in use--you can find all posts and comments at my new blog; I will no longer be posting to this site and comments have been disabled.

Thursday, August 9, 2007

Quota Templates

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

4 comments:

Arun said...

Hi,
Can one set site level and user level quotas also.
Arun

Gary Lapointe said...

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.

Gordon Moller said...

Have been trying to find a method to modify the quota on an existing site collection. Any ideas? WSS 3.0 and/or MOSS 2007.

Gary Lapointe said...

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.