As
you see, you'll probably want to get an idea of how much space is
used on your systems. Ideally, you will monitor capacity installed
as well as free space.
What does the system provide?
Windows NT, 2000, XP and 2003 have built-in support for monitoring
disk space. However, only free space is monitored and only once it
reaches a specific threshold is an event written to the system event
log. But that's it - no admin alert and even the threshold can not
be configured. The Windows 9x variants do not even provide that basic
notification.
So what does this mean? Do we need to purchase a full blown monitoring solution just to keep track of the disk space. Definitely not! Fortunately, Microsoft provides a component called Windows Scripting Host. It is a free component for all flavors of Windows.
What is Scripting Host?
Basically, it is an engine that allows execution of VB script (and even Java Script) outside of a web browser. For those programming script on the web or using Visual Basic, there is not much new. All others need to know at least a bit about scripting to create their own scripts. Not a complex task. And those we don't like scripting at all: relax - a fully functional sample script can be found at the end of this page - ready to run.
With scripting, Microsoft has provided an easy way to automate administrative tasks - like checking the disk space. Scripting host is installed by default on all current Microsoft Windows platforms (like Windows 2000). It is a free download off Microsoft's web site for the older platforms (like Windows NT 4).
How does the script work?
My sample script uses the so-called "FileSystemObject". It is provided by Scripting Host and always present if Scripting Host is installed. It allows to access the file system and has the necessary functionality to - detect which drives are installed in the system
- how much space they offer
- how much free space is left
I take that object and query all drivers present in the system. If
they are hard disk type (e. g. no CD-ROM or diskette), the script
evaluates the total and remaining space. That information is then
formatted in comma-delimited form and added to a string. There is
one line for each disk present in the system.
Finally, that string is send via email to a specific recipient. To send it, I use a small tool - SimpleMail - developed by us. It works with any smtp mail server and is easy to use - ideal for scripting.
Please note that once you have the string, you are not limited to sending it via email. For centralized administration, you can also forward it to a syslog server (e. g. run on Unix) or whatever else you can think of.
The string generated typically looks like
SYSNAME,C,5109346304,136216576
All fields are comma-delimited. The first one is the computer name, the second the drive id (C, D, E, ...) the comes the total space in bytes and the remaining free space. That format can easily be imported into an Excel sheet to create one of these nice charts senior management loves.
Can I automatically schedule it?
Now that we have this nice script, we will make sure that it is run without our help. This is especially true if we would like to monitor several systems. Once again Microsoft has provided the right tool:
You can use the "Scheduled Task" application that comes with the operating system. It is found in the Start menu's "Programs/Accessories/System Tools" folder. Simply start it and click on "Add Scheduled Task" and follow the wizard. When it comes to "Click the program you want to run", click browse and find and select the VB script file (yes, this is a program!). Then follow the wizard and select a schedule, etc. That's all you need to do. Oh, well, one last thing: make sure it runs under an account with sufficient privileges to access the disk statistics!
If your platform does not support the "Scheduled Task" application, you might want to visit the Microsoft site for a free update. Under NT 4, you can alternately use the task scheduler together with it's "at" command line tool. But that is neither cool nor intuitive ;-).
Ready to go?
I mentioned a number of resources in my article. If you would like to follow my route, please visit these sites to obtain a free trial of the components I used to create my script: - ActiveLogger - writes information to NT event log or syslog daemon
Then, copy and paste the following script into your favorite text editor (e.g. Windows Notepad). Save that file with a .vbs extension in order to make it executable. Be sure to change the config settings right at the top of the file.
Sample code for monitoring windows disk space
This script reports the drive usage of all fixed drives on the system it is run. The report will be sent via plain text email to a specified recipient address (see last line in file).
This sample can be used in a production environment to set up an unattended disk utilization report system.
For more information contact Adiscon at http://www.adiscon.com/
Support for SimpleMail is available at http://www.simplemail.adiscon.com/
Constants for drive types
Const Unknown = 0 Const Removable = 1 Const Fixed = 2 Const Remote = 3 Const CDROM = 4 Const RAMDisk = 5
general constants
Const MailServer = "127.0.0.1" ' Mail Server to use for SimpleMail Const MailServerPort = "25" ' SMTP Port used at Mail server (25 is default)
Send a mail message
Sub SendMail(Sender, Recipient, Subject, Message) set o = WScript.CreateObject("Adiscon.SimpleMail.1") o.MailServer = MailServer o.Port = MailServerPort o.Sender = Sender o.Recipient = Recipient o.Subject = Subject o.MessageText = Message a = o.SendEx we do not check the return state here - it wouldn't help if we detect an error! This script is intended to run in the background, so there is little we can do.
End Sub
get current computer name (from system environment variables)
Function GetCurrentComputerName     set oWsh = WScript.CreateObject("WScript.Shell")     set oWshSysEnv = oWsh.Environment("PROCESS")     GetCurrentComputerName = oWshSysEnv("COMPUTERNAME") End Function
' Begin main cod
str = ""
set oFs = WScript.CreateObject("Scripting.FileSystemObject") set oDrives = oFs.Drives strComputerName = GetCurrentComputerName ' get name only once for performance reasons
for each oDrive in oDrives     Select case oDrive.DriveType     Case Fixed      str = str & strComputerName & "," & oDrive.DriveLetter & "," & oDrive.TotalSize & "," & oDrive.FreeSpace & vbcrlf     End Select next
SendMail "bounce@nowhere", "YourEMail@nowhere.dotcom", "Drive Space Report", str
About the Author: Rainer Gerhards works for Adiscon, who offers software for server monitoring. Visit http://www.monitorware.com for more information and free downloads.
|
| From the Forum: | | Outlook 2000 folder issues | Last night when returning to my computer work, on opening Outlook, I received a message stating that the personal.pst could not be accessed and was given the option to create new or copy. Upon creating a new folder, I was told that the user profile had been changed and that some options may not be enabled. The program began to download 160 messages dated back from Nov. (these were archived on another system) None the old rules were accepted.
When trying to open the old personal folder tree, was told the folder was already in use and could not be accessed. ...
|

 |