'==========================================================================
'NAME : System-UPTIME.vbs *
'AUTHOR: Arumugam
'Date : 12/21/2008 *
'Description: *
'============ *
' Reads a text file of computer names and gathers speicfied *
' performance data on each one at the interval defined And *
' repeats until it reaches the user-defined variable limit *
'Requirements: *
'============= *
' A text file that has 1 computername per line must be saved in *
' the path defined by the sPath variable *
' *
'PLS CHANGE THE FOLLOWING AS PER YOUR NEEDS *
'========================================== *
'Domain = Domain on which servers are present *
'flog = Location of output file *
'strPath = Location of servers.txt file *
'==========================================================================
t1=time
On error resume next
'Constant declarations for File I/O
'===================================
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
' File Path Defintion "Pls change this as per your requirements"
'===================================================================
'Path of output file
flog = "D:\Temp\Scripts\Server-Stat- check\UpTime-Results.txt"
'Path of servers.txt file
strPath = "D:\Temp\Scripts\Server-Stat- check\Servers.txt"
'Domain of the servers
Domain="domain1"
'Get Login Credentials
'=====================
Wscript.StdOut.Write "Please enter your user ID:"
strID = Wscript.StdIn.ReadLine
'Append domainname (eg: domain) infront of userid
strUser =Domain&"\"&strID
Set objPassword = CreateObject("ScriptPW.Password")
Wscript.StdOut.Write "Please enter your domain password:"
strPassword = objPassword.GetPassword()
Wscript.Echo
wscript.echo
'Instantiate File System Object
'==============================
set fs = CreateObject("Scripting.FileSystemObject")
set objlog = fs.createtextfile(flog)
'Check if input file exists
if fs.FileExists(strPath) then
'open the servers.txt file for reading server names
set fsInput = fs.OpenTextFile(strPath,ForReading)
objlog.writeline " Server " & vbtab & vbtab & " Last Boot Time " & vbtab & " Active since ?"
objlog.writeline "==========" & vbtab & vbtab & " =================" & vbtab & " =============="
do until fsInput.AtEndOfStream
strComputer=fsInput.readline
'Instantiate the SWbemLocator if remote server s pingable
if PingTest(strComputer,1,1000)="Pass" then
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
'Connect to server
Set objSWbemServices = objSWbemLocator.ConnectServer(strComputer,"root\cimv2",strUser,strPassword)
if err.number = -2147024891 then
wscript.echo err.description
wscript.echo "Invalid login. Please check ur login credentials"
wscript.echo
wscript.echo
wscript.echo "Press any key to exit..!"
wscript.stdin.readline
wscript.quit
end if
'Execute
Set colOperatingSystems = objSWbemServices.ExecQuery("Select * from Win32_OperatingSystem")
For Each objOS in colOperatingSystems
dtmBootup = objOS.LastBootUpTime
dtmLastBootupTime =WMIDateStringToDate(dtmBootup)
dtmSystemUptime = DateDiff("h",dtmLastBootUpTime, Now)
objlog.writeline strComputer & vbtab &vbtab & dtmLastBootupTime & vbtab & vbtab & dtmSystemUptime & "Hours"
Next
set colOperatingSystems=nothing
set objSWbemServices = nothing
set objSWbemLocator = nothing
Else
objlog.writeline strComputer & vbtab &vbtab & " Not Pingable "
End if
loop
else
msgbox "No Input file found"
End if
msgbox "Completed. Results at " &flog&vbtab&datediff("s",t1,time)
'==========================================================================
'FUNCTION NAME:WMIDateStringToDate(dtmBootup)
'Description: converts the systemdate string to Date format string
'
'==========================================================================
Function WMIDateStringToDate(dtmBootup)
WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) _
& " " & Mid (dtmBootup, 9, 2) & ":" & _
Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup, _
13, 2))
End Function
'==========================================================================
'FUNCTION NAME:IsReachable(sComputer, #Pings,TimeOut)
'Description: Attempts to ping each computer name. If successful, Function
' equals true; if ping fails, function equals false.
'==========================================================================
Function PingTest(sComputer, iPings, iTimeOut)
Dim sCommand
Dim oShell
Dim oResult
sCommand="ping -n " & iPings & " -w " & iTimeOut & " " & sComputer
Set oShell = CreateObject("Wscript.Shell")
If iPings = "" Then iPings = 2
If iTimeOut = "" Then iTimeOut = 500
Set oResult = oShell.Exec(sCommand)
Select Case InStr(oResult.StdOut.Readall, "TTL=")
Case 0
PingTest="Fail"
Case Else
PingTest="Pass"
End Select
End Function
Monday, November 9, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment