VB Script to Find the Uptime of the server on the given machines list in text file

on error resume next
Set filesys = CreateObject(“Scripting.FileSystemObject”)
set filetxt1 = filesys.OpenTextFile(“C:\scripts\Serveruptime\Serverlist.txt”,1)

do Until filetxt1.AtEndOfStream
strComputer = filetxt1.Readline
strComputer = trim(strComputer)
set objWMIDateTime = CreateObject(“WbemScripting.SWbemDateTime”)
set objWMI = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)
set colOS = objWMI.InstancesOf(“Win32_OperatingSystem”)

for each objOS in colOS
if err.number = 0 Then
objWMIDateTime.Value = objOS.LastBootUpTime
Wscript.Echo strComputer & ” | ” & objWMIDateTime.GetVarDate
Else
Wscript.Echo strComputer & ” | ”
End If
next
Err.clear
Loop

2 thoughts on “VB Script to Find the Uptime of the server on the given machines list in text file

  1. Use this script;

    Set filesys = CreateObject(“Scripting.FileSystemObject”)
    Set filetxt1 = filesys.OpenTextFile(“server_details.Txt”,1)

    do Until filetxt1.AtEndOfStream
    strComputer = filetxt1.Readline
    strComputer = trim(strComputer)
    set objWMIDateTime = CreateObject(“WbemScripting.SWbemDateTime”)
    set objWMI = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)
    set colOS = objWMI.InstancesOf(“Win32_OperatingSystem”)

    for each objOS in colOS
    if err.number = 0 Then
    objWMIDateTime.Value = objOS.LastBootUpTime
    Wscript.Echo strComputer & ” | ” & objWMIDateTime.GetVarDate
    Else
    Wscript.Echo strComputer & ” | ”
    End If
    next
    Err.clear
    Loop

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s