Login | |
|
 |
Export last logon from machine text file with ping resu... - 9/4/2008 4:31:39 AM
|
|
 |
|
| |
gyancher
Posts: 2
Score: 0
Joined: 9/4/2008
Status: offline
|
Dear all, I am trying to get a vb script together that will read from a .txt file that holds machine names, then ping the computer, checks the last username and login time and then export those results to a Excel spreadsheet. Now I have a script that will read machine names from a machinelist.txt file and then ping the machines and exports the ping results in a Excel spreadsheet. But I like to add the last user login information for those machines as well. I found some AD last login vb scripts that export to Excel and those work nice but I am trying to combine those scripts all in 1. Here's the script I have for exporting ping results from a machinelist.txt file into Excel; [pinglist.vbs] 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" objExcel.Cells(1, 2).Value = "Results" objExcel.Cells(1, 3).Value = "CN" objExcel.Cells(1, 4).Value = "FirstName" objExcel.Cells(1, 5).Value = "LastName" objExcel.Cells(1, 6).Value = "LastLogin" Set Fso = CreateObject("Scripting.FileSystemObject") Set InputFile = fso.OpenTextFile("MachineList.Txt") Do While Not (InputFile.atEndOfStream) HostName = InputFile.ReadLine Set WshShell = WScript.CreateObject("WScript.Shell") Ping = WshShell.Run("ping -n 1 " & HostName, 0, True) 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" End Select 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 and then just put some machine names in a txt file called machinelist.txt any thoughts?
|
|
| |
|
|
|
 |
RE: Export last logon from machine text file with ping ... - 9/10/2008 4:45:44 AM
|
|
 |
|
| |
gyancher
Posts: 2
Score: 0
Joined: 9/4/2008
Status: offline
|
Got a new update on the script: 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 = fso.OpenTextFile("MachineList.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) 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" End Select For Each objHostName in colComputer objExcel.Cells(intRow, 3).Value = objHostName.UserName objExcel.Cells(intRow, 4).Value = objItem.FullName Next 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
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|