We help IT Professionals succeed at work.
Get Started

Remote Low Disk Space

978 Views
Last Modified: 2012-05-05
I have found this code which will go off and list servers and how much disk space they have remaining, is there a way to only show servers where the disk space is a user defined % less than the total space.

Or any other way of doing this, I have 200 servers and want a report generated when servers are running low on disk space which I can then email to the administrators.

Many thanks
Option Explicit
Dim iSpc, strComputer, objWMIService
Dim fso, fsHandle, MyShell,LogFileName, colItems, objItem
Dim strInputFile, objInputFile
Const intForReading = 1
 
strInputFile = "Computers.txt"
 
Set MyShell = CreateObject("Wscript.Shell")
Set fso = Wscript.CreateObject("Scripting.FilesystemObject")
LogFileName= MyShell.SpecialFolders("Desktop") & "\FreeSpace.txt"
set fsHandle = fso.OpenTextFile (LogFileName,8,True)
 
fsHandle.Writeline Date
fsHandle.Writeblanklines 1
 
Set objInputFile = fso.OpenTextFile(strInputFile, intForReading, False)
While Not objInputFile.AtEndOfStream
        strComputer = objInputFile.ReadLine
        Set objWMIService = GetObject _
        ( "winmgmts:\\" & strComputer & "\root\cimv2")
        Set colItems = objWMIService.ExecQuery _
        ("Select * From Win32_LogicalDisk Where DriveType = 3")
        
        fsHandle.WriteLine strComputer
        For Each objItem in colItems 
        'Retrieve free space & convert from uint64
        iSpc = cDbl(objItem.FreeSpace)
        fsHandle.Writeline objItem.DeviceID & " - " _
        & FormatiSpc(iSpc) & " GB free"
        Next
Wend
objInputFile.Close
 
Function FormatiSpc(intSpace) 
  intSpace = intSpace/1024
  intSpace = intSpace/1024
  intSpace = intSpace/1024
  intSpace= FormatNumber(intSpace,1)
  FormatiSpc = intSpace
end Function

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 3 Answers and 9 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE