Technical Article

Script to View Server's Free HD Space

,

This VBScript script lets you display the available disk space in each one of your administered DB servers.

You have to call it with ONE argument: the filename of an archive that contains a list of known servers over which you have administration permissions. 

If you program VBScript, you can put alarms when any drive goes under certain number (see the Limite variable).

The idea is to generate the results to a text file.  I use the script in this way:

"C:\scripts\>cscript sqlhd.vbs server.txt > serverHD.txt"

Server.txt will have the form:

server.txt
==========
SERVER1
SERVER2

The report would have the form:

Available Hard Disk Report
-------------------------------------------------
SERVER1
C:[1181] E:[655]

SERVER2
C:[300]<==ALERT! E:[655]

'SQLHD.vbs
'=== Args: Filename that indicates a text file with the server list
'=== by G.Vinueza (July 2003) gvinueza@yahoo.com Santiago, Chile ===
Delim = chr(9) 
IF Wscript.Arguments.Count = 0 THEN
  MsgBox "Server List Missing", vbCritical
  Wscript.Quit
END IF

SET oServer = CreateObject("SQLDMO.SQLServer")
oServer.LoginSecure = True
'=== FileSystemObjet that reads the Server List. ============
SET fso = CreateObject("Scripting.FileSystemObject")
SET oFileTargets = fso.OpenTextFile(Wscript.Arguments(0),1)
RptType = "S"

Dim oResults
Dim sMessage
Dim CmdCad 
Dim Limite  '== Mínimo antes de alerta.


Limite = 500 '== 500 Mbytes.
Wscript.Echo "Available Hard Disk Report"
Wscript.Echo "-------------------------------------------------"
'=== Processing for each server
On Error Resume Next
DO UNTIL oFileTargets.AtEndOfStream
If Err <> 0 then 
  Wscript.Echo  "Error:" & Err.Description 
  Err.Clear
End IF
  sTarget = oFileTargets.ReadLine
  oServer.Connect sTarget
  SET oJobServer = oServer.JobServer
  Wscript.Echo sTarget 
  '=== Executes the command ========================================================
  CmdCad = "Exec master..xp_fixeddrives"
  Set oResults = oServer.ExecuteWithResults(CmdCad)
  sMessage = ""
  sAvailable = ""
  For J = 1 To oResults.Rows
      sDrive = oResults.GetColumnString(J, 1)
      sAvailable = oResults.GetColumnString(J, 2)
    sMessage = sMessage & sDrive & ":[" & sAvailable & "] "
  if CInt(sAvailable) < Limite then sMessage = sMessage & "<==ALERT!  " 
  Next
  sMessage = sMessage & Chr(13) & Chr(10)
  Wscript.echo sMessage
  '=== Releases memory
  Set oResults = Nothing
  SET oJobServer = Nothing
  oServer.Disconnect
LOOP

''''Clean up'''''
SET oServer = Nothing
SET oFileTargets = Nothing
SET fso = Nothing

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating