Although the way disk quotas are implemented in Windows Server 2003 is certainly an improvement over what we had in Windows 2000, it still lacks some management capabilities. For example, while Windows makes it easier to set up quotas, there are no built-in reporting tools that allow you to see how disk space is being used. Fortunately, there is a simple script that admins can use to report on a server's disk space usage.
I know that scripting can be a bit intimidating to those who are not used to working with scripts on a regular basis, so I'll try to make this as painless as possible.
Two classes of disk quota management
Windows Server 2003 contains two different classes that are related to disk quota management: the Win32_QuotaSetting class and the Win32_DiskQuota class. Both classes contain various properties with values related to the quotas that have been imposed on the system.
If you want to create a report of how disk quotas are being used, all you have to do is to create a script that reads the properties. The interesting thing about these two classes is that -- with the exception of the VolumePath property -- they are all readable and writable. This means that with a little work, you can actually create a script that sets or modifies disk quotas.
Creating a disk quota management script
As you can see, the basic idea behind creating a quota management script is simple. All you have to do is create a script that binds to one of the two classes and then read the values of the various properties. If you don't know how to do that, don't worry -- it's easier than it sounds.
Start out by opening Notepad and entering the following text:
These lines of code take care of binding the Win32_DiskQuota class. To read the properties that are associated with the class, you have to set up a loop that contains a command to
To continue reading for free, register below or login
To read more you must become a member of SearchWindowsServer.com
');
// -->

echo the contents of the property that you are interested in. You need a loop because, typically, multiple quota entries will exist, and if you don't have a loop, then only the first quota entry will be displayed. Again, this is easier than it sounds. Take a look at the text below. The first and last lines in this block of code create the loop:
The middle line in the block of code above echos the value of one of the class properties. In this case, we are echoing the objQuota.User property, which contains the name of the user to whom the quota entry applies. You can modify this command so that it inserts some explanation text in front of the property that is being displayed. For example, if you wanted to insert the word USERNAME: in front of the property, then the command would look something like this:
As you can see, I simply inserted the text that I wanted displayed immediately after the echo command. The text is enclosed in quotation marks and followed by an ampersand.
That's all you have to do to create a basic script. Of course the real trick to creating a useful script is to know what properties are available to you. The properties vary slightly depending on whether you use the Win32_DiskQuota class or the Win32_QuotaSetting class. You can control which class is being used by modifying the end of the last line in the first block of code that I showed you, like so:
The tables below show the properties that are available to you.
Available properties for Win32_QuotaSetting
[TABLE]
Available properties for Win32_DiskQuota
[TABLE]
Now let's put it all together and create a simple script that reports on a user's disk space usage. Here is the sample script:
Enter the script's text into notepad and save it as a .VBS file. In case you are wondering, the empty WSCRIPT.ECHO command near the end of the script simply inserts a blank line before the loop occurs. You can run the script by opening a command prompt window and entering the CSCRIPT.EXE command, followed by the filename that you assigned to your script. Depending on how many users you have, the script may initially appear to lock up; eventually, though, it will produce output similar to what you see in Figure A.
Figure A
[IMAGE]
That is what the script looks like in action. Obviously, this script produces a lot of data. Fortunately, there are a few things you can do to make it more manageable. One option is to use the redirect command to dump the output to a text file. To do so, you would enter the following command when you run the script:
That command would write the output to a text file so that you can view the output at your leisure. Here's another way to modify the script so that the information is filtered. Take a look at the third line of the script above:
The Select statement at the end of this command controls which data the script is going to read (and eventually display). Right now the command is set to select *, which tells Windows to read all of the entries. If you want it to read only the data that you are interested in, you can modify the select statement.
To do so, append the WHERE command to the statement, followed by a property name, an operator and a value. For example, if you only want to see users who are consuming more than 500,000 KB of disk space, then you would modify the command as shown below:
Likewise, you could modify this command so that it only shows you the users who have exceeded their quota. Just make the following modification:
While this may seem like a lot of information, it really only begins to scratch the surface of what is possible with these types of scripts. If you are interested in learning more about quota-related scripts, check out this link from Microsoft.
[TABLE]