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 Microsoft MVP in Windows PowerShell, Microsoft Certified Trainer and an IT veteran with over 20 years of experience, much of it spent as an IT consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He works today as an independent author, trainer and consultant. Jeff writes the popular Prof. PowerShell column for MPCMag.com and is a regular contributor to the Petri IT Knowledgebase and 4SysOps. If he isn't writing, then he's most likely recording training videos for companies like TrainSignal or hanging out in the forums at PowerShell.org. Jeff's latest books are Learn PowerShell 3 in a Month of Lunches, Learn PowerShell Toolmaking in a Month of Lunches and PowerShell in Depth: An Administrators Guide. You can keep up with Jeff at his blog http://jdhitsolutions.com/blog, on Twitter at twitter.com/jeffhicks and on Google Plus (http:/gplus.to/JeffHicks)

comments powered by Disqus

Reader Comments:

Fri, Oct 18, 2013 Gytha share click here to get started

http://www.imnevergettingmarried.com/ DOT http://www.yanniazerbaijan.com/ DOT

Sat, Feb 2, 2013 Snowy cheap california auto insurance 1453 car insurance quotes aepvv

http://www.getyourinsurancequote.net/ DOT 1453 http://www.findcarinsurbrokers.com/ DOT aepvv

Thu, Jan 31, 2013 Jacie cheap auto insurance 6372 car insurance quotes 8-]]

http://www.onlinecheapautoinsur.com/ DOT 6372 http://www.findcarinsurbrokers.com/ DOT 8-]]

Tue, Jan 29, 2013 Boss cialis generic 2164 car insurance quotes 8)

http://www.mensmedicineonline.com/ DOT 2164 http://www.findcarinsurbrokers.com/ DOT 8)

Tue, Jan 29, 2013 Bones car insurance quote 51318 affordable auto insurance >:-[[[

http://www.mycarinsurquote.com/ DOT 51318 http://www.findcarinsurbrokers.com/ DOT >:-[[[

Tue, Jun 22, 2010

Where is the script (redmongmag.com/hicks0210) ?

Fri, Feb 5, 2010 Dan Stalker Tucson AZ

"you can download the script at Redmondmag.com/Hicks0210" - exactly whrer is this?.

Add Your Comment Now:

Your Name:(optional)
Your Email:(optional)
Your Location:(optional)
Comment:
Please type the letters/numbers you see above

Redmond Tech Watch

Sign up for our newsletter.

I agree to this site's Privacy Policy.