Page 1 of 1 1
Topic Options
#87281 - 2002-08-17 11:32 AM Get percent drive space alerts
Douglas Cohn Offline
Lurker

Registered: 2002-08-17
Posts: 1
Loc: New York
How would I create a routine that can notify me when the percentage of available drive space on specified drives falls below a set amount.

I do not care about user or quotas. I just want to know when the drive has less than 15% fee space.

I can schedule it to run every 30 minutes and can email it using smtp or blat but I am lost as to what will give such results.

Thanks

Doug

Top
#87282 - 2002-08-17 01:54 PM Re: Get percent drive space alerts
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
douglas, some of us are trying to find out how to determine the disksize, cause with freediskspace, then your thing can be counted too...

don't remember quickly any script that would do neither, sorry [Frown]

anyway, the easiest way might not just be with com.
easy would mean like dir /s on volume and check those values and count.

[ 17. August 2002, 13:56: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#87283 - 2002-08-17 03:42 PM Re: Get percent drive space alerts
Dunc Offline
Getting the hang of it

Registered: 2002-05-25
Posts: 54
Loc: Guildford England
Douglas

This bit of code may help you. It gets the disk size and freespace for all fixed disks from WMI.

Duncan

code:
$objWMI = GetObject("winmgmts:{impersonationlevel=impersonate}!//" + @WKSTA)


$colDisks = $objWMI.ExecQuery("select * from win32_logicalDisk")
For Each $objDisk In $colDisks

if $objdisk.mediatype <> 12



else


$name = $objdisk.name
$volName = $objDisk.VolumeName
$volfreepace = $objDisk.freespace
$volsize = $objDisk.size

? "Name is: " + $name
? "Volume name is: " + $volName
? "Volume size is: " + $volsize
? "Free space : " + $volfreepace

endif



Next
$objWMI = 0



Top
#87284 - 2002-08-17 03:52 PM Re: Get percent drive space alerts
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
duncan, thanks mate. I might myself use that.

anyway, I'd change:
code:
if $objdisk.mediatype <> 12
else

to:
code:
if $objdisk.mediatype = 12

_________________________
!

download KiXnet

Top
#87285 - 2002-08-17 03:55 PM Re: Get percent drive space alerts
Dunc Offline
Getting the hang of it

Registered: 2002-05-25
Posts: 54
Loc: Guildford England
Lonkero,

Thanks for that, What is also needed it to turn the out put in to KB MB GB, if you divide the out put by 1024 you get an error. Any ideas!

Duncan

Top
#87286 - 2002-08-17 04:06 PM Re: Get percent drive space alerts
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
you get error?
what is your divide code?

blaa blaa
blaa blaa

blub

[ 17. August 2002, 16:11: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#87287 - 2002-08-17 04:08 PM Re: Get percent drive space alerts
Dunc Offline
Getting the hang of it

Registered: 2002-05-25
Posts: 54
Loc: Guildford England
The error is error in expression, and all I am doing is

$mb = $volsize / 1024

Duncan

Top
#87288 - 2002-08-17 04:14 PM Re: Get percent drive space alerts
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
mmm...
try with:
$mb = 0.0 + $volsize / 1024

anyway, the thing is probably that the $volsize is string not numeric.
check it with valtype()
anyway, if you want to translate it to value:
$mb = val($volsize) / 1024

cheers-,-
_________________________
!

download KiXnet

Top
#87289 - 2002-08-17 04:32 PM Re: Get percent drive space alerts
Dunc Offline
Getting the hang of it

Registered: 2002-05-25
Posts: 54
Loc: Guildford England
humm..

The problem with converting from a string is it alters the value and then the info is incorrect. [Mad]

$mb = 0.0 + $volsize / 1024 still come up with same error! [Frown]

Duncan

Top
#87290 - 2002-08-17 04:33 PM Re: Get percent drive space alerts
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ok, can't test currently as playing with my linux-server.

anyway, what is the outcome of the $volsize?

I mean, what it contains as text?
_________________________
!

download KiXnet

Top
#87291 - 2002-08-17 04:33 PM Re: Get percent drive space alerts
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
Duncan,

Assuming you are using KiX 4.1+
Try using the CDbl() and FormatNumber() functions:
code:
$objWMI = GetObject("winmgmts:{impersonationlevel=impersonate}!//" + @WKSTA)

$colDisks = $objWMI.ExecQuery("select * from win32_logicalDisk")
For Each $objDisk In $colDisks
if $objdisk.mediatype = 12
$name = $objdisk.name
$volsize = $objDisk.size
$Kb = CDbl($volsize) / 1024
$Mb = CDbl($Kb) / 1024
? "Name is: " + $name
? "Volume size in bytes is: " + $volsize
? "Volume size in kb is: " + FormatNumber($Kb,1)
? "Volume size in Mb is: " + FormatNumber($Mb,1)
endif
Next
$objWMI = 0

I just tested this code, works on XP

-Erik

Top
#87292 - 2002-08-17 04:40 PM Re: Get percent drive space alerts
Dunc Offline
Getting the hang of it

Registered: 2002-05-25
Posts: 54
Loc: Guildford England
Erik,

Thanks

That works great (Windows 2000).

[Big Grin] [Big Grin] [Big Grin]

Duncan

Top
#87293 - 2002-08-17 05:03 PM Re: Get percent drive space alerts
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I don't know why:
$kb = 0.0 + $volsize / 1024

isn't working.
or should it be:
$kb = 0.0 + val($volsize) / 1024
_________________________
!

download KiXnet

Top
#87294 - 2002-08-17 05:26 PM Re: Get percent drive space alerts
kholm Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
To use implicit typecasting, you can use:

code:
$Kb = (0.0 + $volsize) / 1024

I think you should be very carefull when using Val()
If you use Val() on a variable containing a value bigger than the largest possible integer, you get unpredictable results.

Lonkero,
I know the implicit typecating is a finding from one of the KiX-golf games, but maybe we should be careful when using it on big values.
In this situation we might as well use the CDbl()

The code above works in v. 4.10 and 4.11b2

-Erik

Top
#87295 - 2002-08-17 05:38 PM Re: Get percent drive space alerts
Dunc Offline
Getting the hang of it

Registered: 2002-05-25
Posts: 54
Loc: Guildford England
Douglas,

This should give you the required results. (I need to go away and put this into some of my other scripts now!) [Big Grin]

Thanks for Lonkero's and Erik's help.

Duncan

code:
 


$objWMI = GetObject("winmgmts:{impersonationlevel=impersonate}!//" + @WKSTA)

$colDisks = $objWMI.ExecQuery("select * from win32_logicalDisk")
For Each $objDisk In $colDisks
if $objdisk.mediatype = 12
$name = $objdisk.name
$volsize = $objDisk.size
$freespace = $objDisk.freespace

$freekb = CDbl($freespace) / 1024
$freemb = CDbl($freekb) / 1024

$VolKb = CDbl($volsize) / 1024
$volMb = CDbl($volKb) / 1024

; ? "Name is: " + $name
; ? "Volume size in bytes is: " + $volsize
; ? "Volume size in kb is: " + FormatNumber($volKb,1)
; ? "Volume size in Mb is: " + FormatNumber($volMb,1)


; ? "Free space in bytes is: " + $freespace
; ? "Free space kb is: " + FormatNumber($freeKb,1)
; ? "Free space in Mb is: " + FormatNumber($freeMb,1)

$per = $freemb / $volmb * 100

If $per < 15

messagebox(FormatNumber($per,1)+ "% Disk Space free","Disk Space",48)
Endif

endif

Next
$objWMI = 0





Top
#87296 - 2002-08-17 10:47 PM Re: Get percent drive space alerts
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Why so complicated? This is build into Windows!

Set this registry key to the 'percent free' and set the alert server to whichever computer should receive the alert.
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters\DiskSpaceThreshold=5

See also How can I change the alert for low disk space on a partition?
See this article How can I configure Administrative alerts in Windows 2000? on how to configure administrative alerts (works for Windows NT/2000/XP)

[ 17. August 2002, 22:47: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#87297 - 2002-08-19 11:39 AM Re: Get percent drive space alerts
Dunc Offline
Getting the hang of it

Registered: 2002-05-25
Posts: 54
Loc: Guildford England
sealeopard

Thats fine if you are using NT/2000/XP.

We've still got 11,000 Windows 98 clients!

Unless you know of a way under 98 to do the same.

Still the code has come in usful for other tasks I have in mind as well! [Smile]

Duncan

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 484 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.038 seconds in which 0.013 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org