' ========================================================
' Script Information
'
' Created for:
' Title: Hard Disk Space , CPU and Memory Usage Script
' Author: Jeffrey G. Ablang
' Originally created: 6/19/2008 - 10:58:36
' Original path: PCEWKDB24CF1S D:\share\Coding Project\hdd_cpu_ram_MONv1.csv
' Description: Script to monitor my computers hard disk space, my cpu usage in (%) and memory RAM usage in (%)
'
' ========================================================
Option Explicit
Dim oWsh, oWshSysEnv, objFSO, objWMIService
Dim oDrives, oDrive, objOutFile, colItems, objItem
Dim strLineDate, strLineTime, strLineProcessorTime, strLineDriveSpace, strLinePercentCommittedBytesInUse
Set oWsh = WScript.CreateObject("WScript.Shell")
Set oWshSysEnv = oWsh.Environment("PROCESS")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
strLineDate = Date()
strLineTime = Time()
'Gets PROCESSOR Usage
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name = '_Total'")
For Each objItem In colItems
strLineProcessorTime = strLineProcessorTime & " " & objItem.PercentProcessorTime
Next
'Gets MEMORY Usage
Set colItems = GetObject("WinMgmts:root/cimv2").ExecQuery("Select * FROM Win32_PerfFormattedData_PerfOS_Memory ")
For Each objItem In colItems
strLinePercentCommittedBytesInUse = strLinePercentCommittedBytesInUse & " " & objItem.PercentCommittedBytesInUse
Next
'Gets FREE SPACE Report
Set oDrives = objFSO.Drives
For Each oDrive In oDrives
Select Case oDrive.DriveType
Case 2 'Fixed Drives
strLineDriveSpace = strLineDriveSpace & " " & oDrive.DriveLetter & "\: " & Round(oDrive.FreeSpace / (1024 * 1024)) & "MB free (" & Round(100 * (oDrive.FreeSpace / oDrive.TotalSize), 2) & " %) "
End Select
Next
'Output to text
Set objOutFile = objFSO.OpenTextFile("C:\hdd_cpu_ram_MONv1.csv", 8, True)
objOutFile.WriteLine "Date,Time,Computer Name,Processor Usage (%),Memory Usage (%),Drive Free Space"
objOutFile.WriteLine strLineDate & "," & strLineTime & "," & oWshSysEnv("COMPUTERNAME") & "," & strLineProcessorTime & "," & strLinePercentCommittedBytesInUse & "," & strLineDriveSpace
'WScript.Echo "DONE"
WScript.Quit