Dirquota – Automagically Manage File System Quotas
Did you know that Windows Server contains a file system quota component? “Of course”, you will say. It was introduced with Windows 2000 and is completely useless since it only allows for volume-level quotas. That is true, but at the same time it is nowadays quite irrelevant. With the R2 update to Windows Server 2003 Microsoft finally got it right and introduced the optional component File Server Resource Manager (FSRM). With FSRM, folder-level quotas find their way into the (professional) lives of administrators who do not care for additional third-party filter drivers that are prone to destabilize production servers.
On this note I could conclude this post. After all, FSRM brings a nice GUI for managing those great folder-level quotas. But what about automation? Scriping? For those of you who like to automate tasks and/or have to support large environments I want to provide a few examples.
In order to use FSRM you need either Windows Server 2003 R2 or Server 2008 with the component File Server Resource Manager installed. FSRM can be installed in an unattended setup by adding the following lines to the answer file (usually
SRM = On
Settings Quotas on Home Directories – From the Command Line
On Systems where FSRM is installed the command line utility
dirquota.exe can be used to configure quotas. A very common scenario is to assign quotas to home directories. In order to do that you first need to define a template:
dirquota template add /template:"Home 1 GB" /limit:1GB /type:hard
The example above creates a template that, when assigned to a specific folder, hard limits that folder’s size to 1 GB. The template itself is saved under the name of “Home 1 GB” for later usage. You can, of course, create as many templates as you want.
The next step is to assign the template to a specific folder. That can be done with the following command:
dirquota quota add /path:"D:\Data\Users\Home\UserA" /sourcetemplate:"Home 1 GB"
The example above adds a quota of 1 GB (defined in the template above) to the home directory of UserA.
Being able to set quotas on single directories is quite nice. It does not help very much with home directories, though. What you need is the ability to tie the template to the home folder’s base directory and have it applied to every sub-folder auto-magically. That is exactly what the next command does:
dirquota autoquota add /path:"D:\Data\Users\Home" /sourcetemplate:"Home 1 GB"
FSRM will now put the quota defined in template “Home 1 GB” on every subdirectory that gets created directly below D:\Data\Users\Home.