Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WMI diskspace if less than 10 %

Status
Not open for further replies.

ajtsystems

IS-IT--Management
Jan 15, 2009
80
GB
Hi I have written some code and need to know how to call some additional code if the space left on the disk is less than 10 percent. So far I can get the remainder of the disk in % but my bit where I say if remainder is less then 10% wscript.echo hello doesn't seem to work

Here is what I ave so far


remainder = "10.0%"
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
("Select * from Win32_LogicalDisk Where DeviceID = 'C:'")
For Each objDisk in colDisks
intFreeSpace = objDisk.FreeSpace
intTotalSpace = objDisk.Size
pctFreeSpace = intFreeSpace / intTotalSpace
'Wscript.Echo formatpercent(pctFreeSpace)
actfreespace = formatpercent(pctFreeSpace)
wscript.echo actfreespace




if FormatPercent(pctFreeSpace) > remainder then
wscript.echo "hello"

end if
next
 
Replace this:
if FormatPercent(pctFreeSpace) > remainder then
with this:
If pctFreeSpace < 0.1 Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
HAving a few difficulties, the number returned is sometimes .06 but somtime 6.87E (yes with an E on the end)

Maybe this is whats stopping it from working

james
 
You may try this:
If CDbl(pctFreeSpace) < 0.1 Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
A slight modification to your code...

Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk Where DeviceID = 'C:'")
For Each objDisk in colDisks
    intFreeSpace = objDisk.FreeSpace
    intTotalSpace = objDisk.Size
    intUsedSpace = objDisk.Size - objDisk.FreeSpace
    percent = intTotalSpace * 0.1
    
    If percent > (intTotalSpace - intUsedSpace) Then
        wscript.echo objDisk.Caption & " Less Than 10% Free Space"
    Else
    	wscript.echo objDisk.caption & " More Than 10% Free Space"
    End If
Next



I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top