Ric_ Posted October 24, 2006 Posted October 24, 2006 I have disk quotas set up on the homedrives of my users. These drivers are mapped to H: and take the form of '\\svr1\y7 to y11\username', '\\svr2\y12 to y13\username' and '\\svr2\staff\username'. What I need to do is write a script to pop up a friendly message saying that a user is approaching their quota limit. This does not seem to be as easy as it sounds. If anybody has any ideas, please post!
ChrisH Posted October 24, 2006 Posted October 24, 2006 Umm didnt you write a script like this ages ago? If not you can get the values from WMI or have hardcoded ones. Where is the problem at?
Ric_ Posted October 24, 2006 Author Posted October 24, 2006 @ChrisH: I wrote a 'rough and ready' one that had hard coded values. What I want to do is use the disk quota functionality to determine the amount of space left. I'm having problems querying the WMI disk quota business though
mrtechsystems Posted October 24, 2006 Posted October 24, 2006 Could you please post the script would like this feature in my script would be a usefull thing Thanks
Ric_ Posted October 24, 2006 Author Posted October 24, 2006 Could you please post the script would like this feature in my script would be a usefull thing Thanks I would if I could get it to work!
NetworkGeezer Posted October 24, 2006 Posted October 24, 2006 Doesn't vanilla Windows 200x server give warning anyway?
Ric_ Posted October 24, 2006 Author Posted October 24, 2006 @NetworkGeezer: Don't think so... it tells you when you have reached your hard limit by saying that you have no space left though!
Ric_ Posted October 24, 2006 Author Posted October 24, 2006 OK... I think I'm getting somewhere now. I have discovered the following: * WMI scripting is slow * You cannot find the quota details out off the mapped user drive so you must point your script at the relevant server (hence I have to have my script decide which server to look at first) * To save luser confusion, you need to specify which volume on the server to look at (luckily for me, my pupil homedrives live on drive E: on both servers) The following is my pupil script (the staff one is slightly different because it looks at F: on svr2 only). It needs a little more testing but I think that it should work OK. If this messes anything up I am NOT responsible so test it yourself too! ' Script to check how much disk quota a user has remaining ' and warn if approaching their limit. ' Author: Ric Charlton, 24/10/06 Set WshNetwork = WScript.CreateObject("WScript.Network") strDomainName= WshNetwork.UserDomain strUserName = WshNetwork.UserName If Left(strUserName, 1) = "0" then strComputer = "svr1" Else strComputer = "svr2" End If Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set objQuota = objWMIService.Get _ ("Win32_DiskQuota.QuotaVolume='Win32_LogicalDisk.DeviceID=""E:""'," & _ "User='Win32_Account.Domain=""" & strDomainName & """,Name=""" & strUserName & """'") If objQuota.Status = 1 then WScript.Echo "You are reaching your disk quota limit! " _ & "Consider deleting some of the files in your My Documents folder or see the Network Manager." WScript.Echo "You only have " & (objQuota.Limit - objQuota.DiskSpaceUsed) / 1024 & "MB disk quota remaining!" Else WScript.Echo "You have " & (objQuota.Limit - objQuota.DiskSpaceUsed) / 1024 & "MB disk quota remaining." End If BTW - Users without a disk quota set (i.e. no limit) get an odd looking amount of disk qota remaining message. Edit made!
Ric_ Posted October 24, 2006 Author Posted October 24, 2006 One slight problem is that 'regular' users cannot execute the GetObject command... hence the script doesn't work I will find a way around this though as it's something I really need to keep some of the staff user areas in check!
ChrisH Posted October 31, 2006 Posted October 31, 2006 I noticed with the new R2 features that you can make it email the user or the admin with these details.
mac_shinobi Posted January 3, 2007 Posted January 3, 2007 http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/disk/quotas/#EnumDiskQuotas.htm Also not sure if this will help but instead of using GetObject() would it make any difference if you use WScript.GetObject() In your code Also if you have an if statement to check to see what values are returned for someone who has no limit and for someone who does have a limit on disk quoatas, that way you can check to see using an if statement if the user has a disk quota or not before you do the if statements to give the warning messages so you dont get that funky message at the end. Aside from that do the users have permissions in GPO to run or use scripting activex or scripts ? Just a thought as to why its being stopped. Hopefully this helps a bit
PiqueABoo Posted January 4, 2007 Posted January 4, 2007 If anybody has any ideas, , please post! 1) H: drive looks as big as their quota. 2) WMI is relatively horrible. 3) This is relatively easy: var fso = new ActiveXObject("Scripting.FileSystemObject"); if ( (fso.GetDrive("H:").FreeSpace/fso.GetDrive("H:").TotalSize) < 0.1 ) WScript.Echo("You are approaching your disk quota limit! Blah-blah-blah.."); You need to translate that from JScript.
mac_shinobi Posted January 4, 2007 Posted January 4, 2007 var fso = new ActiveXObject("Scripting.FileSystemObject"); if ( (fso.GetDrive("H:").FreeSpace/fso.GetDrive("H:").TotalSize) < 0.1 ) WScript.Echo("You are approaching your disk quota limit! Blah-blah-blah.."); '--------------- vbscript version ------------ Dim fso Set fso = CreateObject("Scripting.FileSystemObject") if((fso.GetDrive("H:").FreeSpace/fso.GetDrive("H:").TotalSize) < 0.1) Wscript.Echo("You are approaching your disk quota limit! blah - blah") End If See if that works for you
ZeroHour Posted April 18, 2007 Posted April 18, 2007 I am working on a solution involving a client/server approach. Anyone fancy helping in the very early stages add me to MSN and give me a buzz. Not sure on programming languages that I will use but thats kinda to fit the solution then anything. I really need some people to at least run theories past before I implement (and I am to shy to show my foolishness off in forums before thinking it through).
mortstar Posted October 30, 2007 Posted October 30, 2007 I've been reading through a few threads that try to display a dialogue box when quota thresholds are reached on 2k3 R2's File Server Management. I have plagiarised a fair few scripts and none seem to do what I need them to. The closest I came was the simple script: Dim fso Set fso = CreateObject("Scripting.FileSystemObject") Set driveObject = fso.GetDrive("H") if((driveObject.AvailableSpace/driveObject.TotalSize) < 0.1) then Wscript.Echo("You are approaching your disk quota limit!" & driveObject.FreeSpace) else Wscript.Echo("fine " & driveObject.AvailableSpace & " " & driveObject.TotalSize) End If But this is picking up the Used Space and Total Space of the whole network drive, not the quota amount. Has anybody created a vbs script that can tell users that they are approaching their quota limit? I'd love to use email notification but it just wouldn't work until we have improved our email solution. Failing that - R2 can run a command when the thresholds are reached. The command that is put in this box - is it a file local to the server or to the user's machine? You cannot choose files held on network drives.
maniac Posted October 30, 2007 Posted October 30, 2007 This little bit of script I've just cobled together from a couple of others. It gets the disk size from the windows file system, and then calculates the used space from the size of the folders on the drive. I know it can be simplified, but it works and returns the correct values as a message at the moment. I know it's a bit in-accurate on the space used, e.g. it reported 149GB was in use on my test drive, where as windows tells me there's only 146GB, but on smaller quantities of files/folders like a users home area, it should be accurate enough to warn when the quota is low. You need to change the TWO referneces to G: to whatever drive letter you're monitoring. I know this can be put in as a variable, but like I say it was cobbled toegther from two seperate scripts. dim oFS, oFolder set oFS = WScript.CreateObject("Scripting.FileSystemObject") set oFolder = oFS.GetFolder("G:\") Set objWMIService = GetObject("winmgmts:") Set objLogicalDisk = objWMIService.Get("Win32_LogicalDisk.DeviceID='G:'") Wscript.Echo "Space Used=" & int(oFolder.Size /1048576) & " MB" & vbCr & _ "Allowed Space: " & Int(objLogicalDisk.Size /1073741824) & " GB" And yes I have tested it with mapped drives limited by windows quotaing, and it works! Also it's not to slow either. On a 160GB network drive it only took about 3 or 4 seconds to calculate the used space, so on a 1GB user share it's not going to be too slow. Hope it's of use. Mike.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now