'WMIGETQUOTA.VBS 'v1.0 January 2002 'Jeffery Hicks 'jhicks@jdhitsolutions.com http://www.jdhitsolutions.com 'USAGE: cscript wmigetquota.vbs [servername] 'DESC: Get Disk Quota information from the specified server. 'If you don't specify a server, the script defaults to the local server. ' If you specify a remote server, you must run this script under 'credentials that have admin rights On the target server. 'Otherwise, you need to modify the script to use the SWBEMLocator object 'so you can specify alternate credentials. 'NOTES: THIS SCRIPT USES THE WMI DISK QUOTA PROVIDER WHICH IS ONLY AVAILABLE 'ON WINDOWS XP AND THE NEXT VERSION OF WINDOWS SERVER 2003. 'Output is in CSV format: 'ServerName,Volume Name,Domain\User,Status,Disk Space Used,Quota Limit,Quota Warning 'If you want to save the output, use command line redirection: ' cscript wmigetquota.vbs File01 >> File01Quota.csv 'It is important you use >> so that each entry is appended to the file. 'Strongly recommend you use CSCRIPT to run this. 'Enhancement suggestions if you feel inclined: ' Add date/time stamp to output ' Save results to file using FileSystemObject ' Output to html ' Output to Excel ' Calculate user's percentage available of their quota ' Filter output to only show users at a certain level ' Add code to email Administrators and/or users when quota usage reaches ' a certain level. ' Modify to allow alternate credentials ' License :: ' Copyright 2004 JDH Information Technology Solutions, Inc. ' This program is free software; you can redistribute it and/or modify ' it under the terms of the GNU General Public License as published by ' the Free Software Foundation; either version 2 of the License, or ' (at your option) any later version. ' This program is distributed in the hope that it will be useful, ' but WITHOUT ANY WARRANTY; without even the implied warranty of ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ' GNU General Public License for more details at HTTP://www.gnu.org/licenses/gpl.txt ' ********************************************************************************* ' * DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED IN A SECURED LAB * ' * ENVIRONMENT. USE AT YOUR OWN RISK. * ' ********************************************************************************* On Error Resume Next Dim objSvc, objRet 'If Limit or Warning limit is set to the following constant 'that indicates No Limit has been set Const iLimit="18446744073709551615" If wscript.Arguments.Count=0 Then dim wshnet set wshnet=CreateObject("Wscript.Network") strSrv=wshnet.ComputerName set wshnet=Nothing Else strSrv=UCASE(wscript.Arguments(0)) End If s=VBCRLF set objSvc=GetObject("WinMgmts://" & strSrv) if err.number <>0 then s=s & "OOPS!! There was an error connecting to " & strSrv & VBCRLF & _ "Error# " & err.number & VBCRLF & _ "Error Desc. (if available): " & VBCRLF & _ vbtab & err.description & VBCRLF & _ "Error Src (if available): " & VBCRLF & _ vbtab & err.source wscript.echo s wscript.quit end if Set objRet=objSvc.InstancesOf("win32_DiskQuota") if err.number <>0 then s=s & "OOPS!! There was an error getting Disk Quota information from " & strSrv & VBCRLF & _ "Error# " & err.number & VBCRLF & _ "Error Desc. (if available): " & VBCRLF & _ vbtab & err.description & VBCRLF & _ "Error Src (if available): " & VBCRLF & _ vbtab & err.source wscript.echo s wscript.quit end if wscript.echo "Server,Volume,User,Status,DiskUsed,Limit,Warning" For Each x In objRet If x.Limit=iLimit Then strLimit="No Limit" Else strLimit=ConvBtoMB(x.Limit) End If If x.WarningLimit=iLimit Then strWarnLimit="No Limit" Else strWarnLimit=ConvBtoMB(x.WarningLimit) End If wscript.echo strSrv & "," & RIGHT(x.QuotaVolume,4) & "," & _ ConvName(x.User) & "," & x.Status & "," & ConvBtoMB(x.DiskSpaceUsed) & _ "," & strLimit & "," & strWarnLimit Next set objSvc=Nothing set objRet=Nothing wscript.quit '//////////////////////////////////////////////////////////////////////// 'Functions Function ConvBtoMB(iBytes) 'Convert number of bytes to megabytes On Error Resume Next 'Add "" to result so that long numbers can contain commas and 'not cause misformatting when opening a csv file in Excel ConvBtoMB=CHR(34) & FormatNumber(iBytes/1048576,2)& "MB" & CHR(34) End Function Function ConvName(strWMIUser) 'Convert WMI name string to domain\user On Error Resume Next a=InStr(strWMIUser,",") b=Left(strWMIUser,a) 'win32_Account.Domain= is 22 characters long 'Get domain component strDom=MID(strWMIUser,22,a-22) 'parse out "" strDom=MID(strDom,2,LEN(strDom)-2) c=InStr(22,strWMIUser,"=") strUsr=MID(strWMIUser,c+2) strUsr=LEFT(strUsr,LEN(strUsr)-1) ConvName=strDom & "\" & strUsr End Function 'EOF