Mr. Roboto

Easy Quota Reporting

Microsoft's quota service has its limitations, but you can't beat the price (free).

Microsoft's free quota service is easy to set up, has little in the way of a performance penalty and offers some very useful information. While many use the quota feature to limit how much disk space a user can consume, it's useful even if you don't set limits. For example, even without setting warning and threshold levels, the quota feature can tell how much disk space a user is taking.

Certainly there are third-party quota solutions on the market that can overcome some of the limitations of the Microsoft offering, which include the restriction of working only on a per-volume basis. But you can't beat the price of Microsoft's quota service.

One drawback of the Microsoft quota feature is limited reporting. You can view a decent graphical report, but to get that information into any other format is very difficult. Fortunately, Mr. Roboto knows a little bit about Windows Management Instrumentation (WMI) and Windows PowerShell. I've combined these into an easy-to-use PowerShell function called Get-DiskQuota that you can use just like a cmdlet; you can download the script here.

To run the script, you must be running PowerShell 2.0. I'm going to assume you're working "smarter" and will be managing servers from your desktop. You must also have an account that has administrative credentials on the remote server or servers. The function will accept a PSCredential object for alternate credentials. I recommend creating a PSCredential variable that you can re-use as needed:

PS C:\> $admin=get-credential 
mydomain\administrator

The function doesn't take advantage of the remoting features in PowerShell 2.0, so nothing needs to be installed on the remote servers. However, the WMI service must be running, and you must have remote procedure call connectivity to the server. Use WBEMTEST.EXE to verify or troubleshoot connectivity problems.

The Get-DiskQuota script doesn't do anything on its own other than define an alias -- gdq, for the Get-DiskQuota function -- and the function itself. You'll need to dot source the script file to load the function into your PowerShell session, or copy and paste the function to your PowerShell profile:

PS C:\> . c:\scripts\get-diskquota-
v2.ps1

The dot tells PowerShell: "Take any defined functions, variables, aliases and so forth, and put them in the current scope." Change the path to match where you saved the file. If you don't see any errors, you should be able to view the function's help like any other cmdlet:

PS C:\> help get-diskquota -full

The function is, in fact, written like a cmdlet and accepts several parameters to customize its behavior. More than likely you'll want to specify a server you wish to query:

PS C:\> get-diskquota server01

The function will create a WMI query for the Win32_DiskQuota class for entries that haven't been set to have unlimited entries. The function will also return a custom object for each user from each volume on the server. This will show how much space the user is using; how much space he has remaining; and whether he's over any limits. I made an assumption that an IT pro would only be interested in end-user information, so no quota information is returned for Administrator or the Domain Admins groups.

The rest of the function's parameters are used to filter the output. The function builds an appropriate WMI query based on the values provided.

Suppose, for example, that you only want quota information for drive G for all users, and you need to specify alternate credentials:

PS C:\> get-diskquota server01 
-volume g: -credential $admin

I encourage you to open Get-DiskQuota-v2.ps1 in your script editor and explore the nitty-gritty details. If you have questions about the script, techniques I used or problems you're having developing your own PowerShell tools, please stop by the forums at ScriptingAnswers.com.

About the Author

Jeffery Hicks is a multi-year Microsoft MVP in Windows PowerShell, Microsoft Certified Professional and an IT veteran with almost 25 years of experience, much of it spent as an IT infrastructure consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He works today as an independent author, trainer and consultant. Jeff is a regular contributor to a variety on online sites, as well as frequent speaker at technology conferences and user groups. Keep up with Jeff and his projects at http://jdhitsolutions.com/blog.

comments powered by Disqus
Upcoming Events

Redmond Tech Watch

Sign up for our newsletter.

I agree to this site's Privacy Policy.