Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Server Uptime and Capacity Usage - Help

Status
Not open for further replies.

Kamote26

IS-IT--Management
Jul 29, 2017
1
PH
I have this below script, but i just copied them from another script. I thought if I them on a single file or script, I would be able to get the output.
To be honest I don't have knowledge or skill with scripting, just copying and patse from the internet. Appreciate if you could help me please.

Private Function GetPercentFreeDiskSpace()
Dim colItems
Dim objItem

On Error Resume Next

Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Volume where DriveLetter = 'C:'")

For Each objItem In colItems
GetPercentFreeDiskSpace = Round((objItem.FreeSpace / objItem.Capacity) * 100, 2)
Next

Err.Clear
End Function

Private Function GetMemoryUsage()
Dim colItems
Dim objItem
Dim localtime

On Error Resume Next

Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem")

For Each objItem In colItems
GetMemoryUsage = Round(((objItem.TotalVisibleMemorySize - objItem.FreePhysicalMemory) / objItem.TotalVisibleMemorySize) * 100, 2)
SysUptime = objItem.LastBootUpTime
localtime = objItem.LocalDateTime
SysUptime = WMIDateStringToDate(SysUptime)
localtime = WMIDateStringToDate(localtime)
SysUptime = DateDiff("n", SysUptime, localtime)
SysUptime = timeConversion(SysUptime)
Next

Err.Clear
End Function

Private Function GetAverageCPULoad()
Dim colItems
Dim objItem
Dim ctr
Dim reading(4)
Dim total

On Error Resume Next

For ctr = 0 to 4
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor")

For Each objItem In colItems
If objItem.DeviceID = "CPU0" Then
reading(ctr) = objItem.LoadPercentage
End If
Next
WScript.Sleep 2000
Next

total = 0
For ctr = 0 to 4
total = total + reading(ctr)
Next

GetAverageCPULoad = total / 5

If Err.Number <> 0 Then
Err.Clear
GetAverageCPULoad = ""
End If
End Function

WScript.Echo "Avg. CPU Utilization (%)): " & values(0)
WScript.Echo "Memory Utilization (%): " & values(1)
WScript.Echo "C Drive Utilization (%): " & values(2)
WScript.Echo "System Uptime (hrs): " & values(3)
 
For starters, you need to define objWMIService, so add this code to the top each of the functions.
Code:
Dim strComputer, objWMIService
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

When you retrieve the values at the bottom, you are referencing an array values() that does not exist. You would need to echo the value from the function, like:
Code:
WScript.Echo "Avg. CPU Utilization (%)): " & GetAverageCPULoad()

What are you trying to do with the information, just display it on the screen?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top