Winscripter
  WSH
  Forums
  Downloads
  Books
  Links
  Amazon




Login
Register

© winscripter.com
1998-2004







Script: Create HTML Page of Free Space on Each Drive

Posted by on Monday, January 19, 2004 (PST)

Script: Creates an HTML page which shows the total drive space, free space, and used space.

 

/**
 *     Script:  FreeSpace.js
 *    Purpose:  Displays Total Size, Free Space, Volume Label of Hard Drives
 *              by creating an html file.  Could be used by network admin to
 *              monitor drive storage.
 *     Author:  Daren Thiel
 *       Date:  15 January 1999
 *        Web: 
http://www.winscripter.com
 *       Note:  Rename this file FreeSpace.js
 **/
 
 
 /* Create Shell Object */
//ws = WScript.CreateObject( "WScript.Shell" );
 
 /* Create constants for FileSystem */
 var forReading = 1;
 var forWriting = 2;
 var forAppending = 8;
 
 /* Create File System Object */
 fso = new ActiveXObject( "Scripting.FileSystemObject" );
 
 /* Create Output File */
 var reportFile = "drvspace.htm";
 rf = fso.OpenTextFile( reportFile, forWriting, true );// true - create file
 /* Get a list of drives */
 e = new Enumerator( fso.Drives );
 
 /* Create JScript Object for Drive Information */
function driveInfo( drive )
{
  this.total       = Math.round( drive.TotalSize / 1048576 );
 this.free        = Math.round( drive.FreeSpace / 1048576 );
 this.used        = ( this.total - this.free );
 this.percentUsed = Math.round( ( this.used / this.total ) * 100 );
 this.volumeName  = drive.VolumeName;
 this.letter      = drive.DriveLetter;
}
 
 /* Create HTML Header */
 var mdate = new Date();
 rf.WriteLine( "<html>\r\n<head>\r\n<title>Drive Report - " );
 rf.WriteLine( mdate + "</title>\r\n</head><body>\r\n\r\n" );
 rf.WriteLine( "<font face=verdana size=-1>" );
 
 rf.WriteLine( "<center><font face=verdana size=+2>" );
 rf.WriteLine( "Drive Space Report<br>" );
 rf.WriteLine( "Date: " + mdate + "<br><br>" )
 rf.WriteLine( "</font>" );
 
 /* Loop Through Drives */
for(; !e.atEnd(); e.moveNext() )
{
  drive = e.item();
 
  /* Test to see is drive is available */
  if ( drive.IsReady )
  {
   /* Create JScript Object for drive info */
   drv = new driveInfo( drive );
  
   /* Create Border Table */
   rf.WriteLine( "<table border=5 cellpadding=0 cellspacing=0> <tr><td>" );
 
   /* Create Table Header */
   rf.WriteLine( "<table border=0 cellpadding=2 cellspacing=2 width=500>" );
  
   /* Drive Letter */
   rf.WriteLine( "<tr><td bgcolor=lighttan colspan=4 align=center>" );
   rf.WriteLine( "<font face=verdana size=-1 color=white><b>Drive: " );
   rf.WriteLine( drv.letter + "</td></tr>" );
  
   /* Volume Name */
   rf.WriteLine( "<tr><td width=125 bgcolor=lightgrey>" );
   rf.WriteLine( "<font face=verdana size=-1>Volume Name: </td>" );
   rf.WriteLine( "<td bgcolor=lightblue><font face=verdana size=-1><b>" );
   rf.WriteLine( drv.volumeName + " </td>" );
    /* Total Size */
   rf.WriteLine( "<td width=125 bgcolor=lightgrey>" );
   rf.WriteLine( "<font face=verdana size=-1>Total Size: </td>" );
  rf.WriteLine( "<td bgcolor=lightblue><font face=verdana size=-1><b>" );
  rf.WriteLine( drv.total + "MB</td>" );
  
   /* Used Space */
   rf.WriteLine( "<tr><td width=125 bgcolor=lightgrey>" );
   rf.WriteLine( "<font face=verdana size=-1>Used Space: </td>" );
   rf.WriteLine( "<td bgcolor=lightblue><font face=verdana size=-1><b>" );
   rf.WriteLine( drv.used + "MB</td>" );
  
   /* Free Space */
   rf.WriteLine( "<td width=125 bgcolor=lightgrey>" );
   rf.WriteLine( "<font face=verdana size=-1>Free Space: </td>" );
   rf.WriteLine( "<td bgcolor=lightblue><font face=verdana size=-1><b>" );
   rf.WriteLine( drv.free + "MB</td></tr>" );
    /* Close Table */
   rf.WriteLine( "</table>\r\n\r\n" );
  
   /* Close Border Table*/
   rf.WriteLine( "</td></tr></table>" );
  
  
   /* Create table for bar graph */
   rf.WriteLine( "<table border=5 cellpadding=0 cellspacing=0><tr><td>" );
   rf.WriteLine( "<table width=500 height=5 border=0 " );
   rf.WriteLine( "cellpadding=0 cellspacing=0>\r\n" );
   rf.WriteLine( "<tr><td bgcolor=blue width=" + drv.percentUsed + "%" )
   rf.WriteLine( " align=center><font face=verdana color=white><b>" );
   rf.WriteLine( drv.used +"MB</td>\r\n" );
  rf.WriteLine( "<td bgcolor=purple align=center>" );
   rf.WriteLine( "<font face=verdana color=white><b>" + drv.free );
  
   if( drv.percentUsed > 90 ){
    rf.WriteLine( "</td></tr>" );
   } else {
    rf.WriteLine( "MB</td></tr>" );
   }
   rf.WriteLine( "</table>\r\n\r\n" );
   rf.WriteLine( "</td></tr></table>" );
  

   /* Write a separator */
   rf.WriteLine( "<br><br>" );
}
  /* Test for Mapped Drive */
  else if ( drive.DriveType == 3 )
  {
  rf.WriteLine( "Share" );
  }
  /* Otherwise assume drive is not ready */
  else
  {
  //rf.WriteLine( "Drive: " + drive.DriveLetter + ":\\ Drive Not Ready" );
  }
}
 
 /* Close Table */
 rf.WriteLine( "</table>\r\n</center>" );
 
 /* Close HTML */
 rf.WriteLine( "</body></html>" );
 
 /* Close the File Stream */
 rf.Close();
 
 /* Tell the user we are done */
 WScript.Echo( "Finished" );
 

 


Comments:

Great script! Modifications?
By qstick777 on Wednesday, August 11, 2004 (PST)

First, let me preface this by stating that I have very little experience scripting.  I've gotten as far as purchasing the Win 2000 Scripting Guide and copying about 2 scripts.  I wish I could get further, but I haven't been able to find the time to get more involved.  Having said that:

 

This script works great, but how would I go about modifying it for the following:

 

1) do away with the "ok" box at the end - need it to run in background and not prompt when finished.

 

2) output information to a text file (maybe .csv file) instead of html (least important - I actually prefer the graphical output)

 

3) have output file include computer name in the file name (ie: server01_drvspace.htm)

 

4) have output file copied to a folder on a network share?

 

 

Basically, I have a need to be able to collect this information on several hundred remote servers, but have the information collected on a local server, with a separate file for each server.  Modification #2 is the least important, as I have a feeling that each file is going to have to be viewed and entered into another piece of software.

 

Here is what I had planned to do:

 

push out a reg key (run once) to run this script from a networked share (eg: \\fileserver\public\serverinfo\freespace.js),

log into each server to run the file (hopefully get somebody else in the department to do this for me ;) )

enter the data into the database/spreadsheet (whatever the boss wants) as time permits.  I just really don't want to have to go to each server and collect the information manually.

 

Thanks in advance for any help!

 

Quintin.

Using UNC Paths
By mt_100 on Friday, October 27, 2006 (PST)
This script is great and I would love to use it with a list of UNC paths. Is there a way to change it to use a UNC path as the drive variable? Thanks!



WSH and ADSI Administrative Scripting

New Articles
  • List installed COM objects and associated ProgIDs
    Script: Lists all COM Objects and their associated ProgIDs (If available). Win32_ClassicCOMClassSetting

  • Script: File Rotator
    Script: Rotate files where the most current file has the lowest number in the archive. When files exceed the retention period, they are deleted. Typically used for log files, backups, etc..

  • Script: Create IIS Website and DNS record
    Script: Dan Casier sent me this script that will create a website and appropriate DNS record. The script is intended for Windows 2000 Server with local DNS and necessary DNS mof installed.


  • Winscripter   |  WSH   |  Forums   |  Downloads   |  Books   |  Links   |  Amazon