Login   Search
Skip Navigation Links
Home
Application Security Tips
Oracle , PL/SQL
IT Product Reviews
Project Management
Forum
Contact Us
Links & References
Avoid SQL Injection attack
Threats and Countermeasures: S.T.R.I.D.E
Input Validation
Session Management
Authentication Mechanism
Cross Site Scripting Vulnerabilities
Configuration Management
Scroll up
Scroll down
Oracle 9i - Programming basics PL/SQL
PL/SQL - Conditional Statements – IF
PL/SQL -Nested Block
LOOPS in PL/SQL
PL/SQL Records
Cursors in PL/SQL
PL/SQL Tables
PL/SQL Exceptions
PL/SQL Procedures
PL/SQL Functions
Oracle supplied packages
Packages
PL/SQL Ref Cursors
Types in Oracle PL/SQL
Varrays
Nested Table
Bfile and LOBs
Bulk Binding
Know Depandencies
PL/SQL Wrapper
Triggers
Scroll up
Scroll down
DBMS_SQL package
DBMS_DDL Package
DBMS_JOB Package
UTL_FILE Package
DBMS_METADATA Package
DBMS_PIPE Package
DBMS_SESSION Package
Scroll up
Scroll down

 

Blog

  • Imperativeness of agile methodology in software development
  • Get list of installed softwares on machines in your network
  • VMWare - Error - the vmware authorization service is not running
  • Add chart / graphs in ASP.net application / website
  • Microsoft Ramp Up

Blog

  • Review: uCertify.com: PrepKit for: 70-529 (C#)
  • Bird eye Review: uCertify.com: PrepKit for: 70-529 (C#)
Skip Navigation Links

> Blog entries about: WMI
Check free disk of your servers / computers on network

Since few days I was facing a problem that some of the servers were short of free space due to disk full.

I was looking for quick & simple way to monitor free space on server. I found some sripts on internet & modified it to suit my requirement .

Below script connects to all listed servers using WMI query , creates a report on c:\ . It can also email the report if you want.

How to use this script ?

  • Copy below code in notepad 
  • List names of computers / server in arrServers .
  • Set flag for email true / false & settings for email server
  • Save file as HDDSpaceCheck.vbs file. 
  • Double click vbs file . It shall show report in minute or so depending on number of servers.
  • You can use windows scheduled task to schedule this activity & get email notification .

 

' ******************** Start of Script *************

' Author : Rahul S Bagal  07/13/2009
' This Script Checks Free Disk space in servers defined in "arrServers "


' Define Names of servers to be checked for disk space
arrServers = Array("Server1","Server2","Server3","Server4")

' Email Settings

Const SendEmail = True    ' Turn this flag to false you you do not wish to receive the report in email
const DisplayReportOnScreen  =  True  ' Turn this flag if you do not want to open the created report file. 

strServer = "MailserverName"
intPort = 25
strFrom = "
DoNotReply@domain.com"   ' Set from Email address for email reports
strTo = "
YourName@domain.com"       ' Set to email address where you wish to receive email

' Report File defination
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

' This is the file name where email
strFilePath = "C:\HDDRerport" & Month ( now ) & Day(now) & year(now) & ".txt"


'The WMI query bit...
For i = LBound(arrServers) To UBound(arrServers)
 strBody = strBody & "Please find below a report on local disks for server : " & arrServers(i) & vbCrLf & vbCrLf
 On Error Resume Next
 Set objWMI = GetObject("winmgmts:\\" & arrServers(i) & "\root\cimv2")
 Set colDisks = objWMI.ExecQuery("Select * from Win32_LogicalDisk Where DriveType=3")' Where DeviceID = '" & strDiskLetter & "'")
 If Err.Number = 0 Then
  For Each objDisk in colDisks
   strBody = strBody & "Drive " & objDisk.DeviceID & " - " & vbTab & "Total Size(MB): " & bytesToMB(objDisk.Size) _
    & vbTab & vbTab & "Free Space(MB): " & bytesToMB(objDisk.FreeSpace) & vbtab & " Free Space ( % ) : " & round( bytesToMB(objDisk.FreeSpace) / bytesToMB(objDisk.Size) * 100 , 2 ) & vbcrlf
  Next
 Else
  strBody = strBody & "!ERROR! connecting to " & arrServers(i) & ". " & Err.Number & " - " & Err.Description
  Err.Clear
 End If
 strBody = strBody & vbCrLf & vbCrLf
Next

' Write to File

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    (strFilePath , ForWriting , True)
objTextFile.WriteLine("Server Disk Space Report" & vbCrLf )
objTextFile.WriteLine(strBody )
objTextFile.Close
set objFSO = nothing

'email Section

if SendEmail = True then 
 On Error Goto 0
 Set objMail = CreateObject("CDO.Message")
 With objMail
  .Subject = "Server Disk Space Report"
  .From = strFrom
  .To = strTo
  .TextBody = strBody
  .Configuration.Fields.Item("
http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 '2 = use a specified SMTP server, 1 = use local SMTP service
  .Configuration.Fields.Item("
http://schemas.microsoft.com/cdo/configuration/smtpserver") = strServer 'Your SMTP Server
  .Configuration.Fields.Item("
http://schemas.microsoft.com/cdo/configuration/smtpserverport") = intPort 'Server port
  .Configuration.Fields.Update
  .Send
 End With
end if

Set objMail = Nothing
Set objWMI = Nothing
Set colDisks = Nothing
Set objNet = Nothing


' Display report if flag is set

if DisplayReportOnScreen = True then
 Dim WshShell
 Set WshShell = WScript.CreateObject("WScript.Shell")
 WshShell.Run strFilePath
 Set WshShell = nothing
end if

Function bytesToMB(intbytes)
 bytesToMB = FormatNumber((intbytes / 1024) / 1024,,,,-1)
End Function

' ******************** End of Script *************

{7/13/2009 5:16 AM} {0 comments}  {Tags: Programming, WMI, VB Script, Tips & Tricks}



Designed & Developed by Rahul Bagal