Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Server Uptime and Capacity Usage - Help

Server Uptime and Capacity Usage - Help

Server Uptime and Capacity Usage - Help

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)

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)

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
WScript.Sleep 2000

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

GetAverageCPULoad = total / 5

If Err.Number <> 0 Then
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)

RE: Server Uptime and Capacity Usage - Help

For starters, you need to define objWMIService, so add this code to the top each of the functions.


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:


WScript.Echo "Avg. CPU Utilization (%)): " & GetAverageCPULoad() 

What are you trying to do with the information, just display it on the screen?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close