ByronJohnson
MIS
How would I add a rule to skip all unvailable machines? If the ping result is could not find host the script fails.
Thank you
Set objExcel = CreateObject("Excel.Application") ' Sub to make Excel Document
objExcel.Visible = True
objExcel.Workbooks.Add
intRow = 2
objExcel.Cells(1, 1).Value = "Machine Name" ' Set name in A1 for HostName
objExcel.Cells(1, 2).Value = "Results" ' Set name in A2 for Ping results
objExcel.Cells(1, 3).Value = "Logged-on user" ' Set UserName
Set Fso = CreateObject("Scripting.FileSystemObject") ' Sub to read from file
Set InputFile = fspenTextFile("\\denfs16\dencommon\Sysad\CheckList\Byron\Inventory\DesktopsTest.Txt") ' Select fire to open
Do While Not (InputFile.atEndOfStream)
HostName = InputFile.ReadLine ' Set the Hostname from machinelist.txt
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & HostName & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
Set WshShell = WScript.CreateObject("WScript.Shell")
Ping = WshShell.Run("ping -n 1 " & HostName, 0, True)
If Ping = 1 Then
objExcel.Cells(intRow, 2).Value = "Unavailable"
Else
objExcel.Cells(intRow, 1).Value = HostName
Select Case Ping
Case 0 objExcel.Cells(intRow, 2).Value = "On Line"
Case 1 objExcel.Cells(intRow, 2).Value = "Off Line"
Case 2 objExcel.Cells(intRow, 2).Value = "NA"
End Select
For Each objHostName in colComputer
objExcel.Cells(intRow, 3).Value = objHostName.UserName
'objExcel.Cells(intRow, 4).Value = objItem.FullName
Next
End IF
intRow = intRow + 1
Loop
objExcel.Range("A1:F1").Select
objExcel.Selection.Interior.ColorIndex = 19
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit
Thank you
Set objExcel = CreateObject("Excel.Application") ' Sub to make Excel Document
objExcel.Visible = True
objExcel.Workbooks.Add
intRow = 2
objExcel.Cells(1, 1).Value = "Machine Name" ' Set name in A1 for HostName
objExcel.Cells(1, 2).Value = "Results" ' Set name in A2 for Ping results
objExcel.Cells(1, 3).Value = "Logged-on user" ' Set UserName
Set Fso = CreateObject("Scripting.FileSystemObject") ' Sub to read from file
Set InputFile = fspenTextFile("\\denfs16\dencommon\Sysad\CheckList\Byron\Inventory\DesktopsTest.Txt") ' Select fire to open
Do While Not (InputFile.atEndOfStream)
HostName = InputFile.ReadLine ' Set the Hostname from machinelist.txt
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & HostName & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
Set WshShell = WScript.CreateObject("WScript.Shell")
Ping = WshShell.Run("ping -n 1 " & HostName, 0, True)
If Ping = 1 Then
objExcel.Cells(intRow, 2).Value = "Unavailable"
Else
objExcel.Cells(intRow, 1).Value = HostName
Select Case Ping
Case 0 objExcel.Cells(intRow, 2).Value = "On Line"
Case 1 objExcel.Cells(intRow, 2).Value = "Off Line"
Case 2 objExcel.Cells(intRow, 2).Value = "NA"
End Select
For Each objHostName in colComputer
objExcel.Cells(intRow, 3).Value = objHostName.UserName
'objExcel.Cells(intRow, 4).Value = objItem.FullName
Next
End IF
intRow = intRow + 1
Loop
objExcel.Range("A1:F1").Select
objExcel.Selection.Interior.ColorIndex = 19
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit