Home > Windows Server Tips > Windows Systems and Network Administration > Windows scripting secrets for disk quota management
Windows Server Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

WINDOWS SYSTEMS AND NETWORK ADMINISTRATION

Windows scripting secrets for disk quota management


Brien M. Posey, Contributor
02.13.2008
Rating: -4.50- (out of 5)


Expert advice on Windows-based systems and hardware
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google




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


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


RELATED CONTENT
Windows Management Instrumentation (WMI) Scripting
Windows scripting tutorials for systems administrators
Working with WMI providers to PowerShell
Customizing a mapped drive inventory
Vista's Windows kill switch: What to do if RFM kicks in
Why you should care about Windows PowerShell
Defrag script for all volumes
Christa Anderson's Scripting School for Windows administrators
Microsoft tool exposes WMI namespaces and properties
Microsoft utility helps admins diagnose WMI services
Scripting School: Enhancing scripts that require user input

Windows Data Storage Administration Tools
Using NTFS on a non-Windows OS with NTFS-3G
eZines and eBooks for Windows server professionals
How to keep IIS logs from filling up your server hard drives
Server Message Block 2.0: A new protocol for the millennium
Top Windows storage improvements for cutting costs in '09
Breaking down the Windows Server Backup tool for Windows 2008
A first look at Storage Explorer for Windows Server 2008
Top 10 Windows storage management tips of 2007
Exploring the Windows Server 2003 Resource Kit: Compress.exe and Expand.exe
How to use the g4u network-based hard disk cloning utility

Windows File Management
Using NTFS on a non-Windows OS with NTFS-3G
File classification the automated way with Windows Server 2008 R2
Using DFS to create file system virtualization in Windows Server 2008
File server migration tips for Windows Server 2008
Windows Distributed File System (DFS) Tutorial
Planning a file server migration to Windows 2008
Windows Distributed File System (DFS) Namespace primer
Self-healing NTFS keeps admins one step ahead of data corruption
Windows NTFS Tutorial
Windows registry hack improves offline file access for mobile users
Windows File Management Research

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
NTFS  (SearchWindowsServer.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


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]

Rate this Tip
To rate tips, you must be a member of SearchWindowsServer.com.
Register now to start rating these tips. Log in if you are already a member.




DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Server Room Design - Planning, Cooling, Maintenance
HomeTopicsBlogsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2004 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts