• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 422
  • Last Modified:

Script to export OS type and machine IP's

is there a script to input a computer name from a txt\csv\input box and export it's full windows version and IP's?
  • 3
1 Solution
Paste the script below into a text file with a .vbs extension.  Customize the contents of the arrComputers array on line 1 with the target computer names.  Running the script will query each machine and write output to a comma-delimited text file.

arrComputers = Array("computer1","computer2")
strReport = "report.csv"
On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objReport = objFSO.CreateTextFile(strReport, True)
objReport.WriteLine "Computer,OS Name,OS Version,IP"
For Each strComputer in arrComputers
    If PingCheck(strComputer, 1, 500) Then
        Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
        Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
        For Each objItem in colItems
            strOSName = Trim(objItem.Caption)
            strOSVer = Trim(objItem.Version)
        Set colItems = objWMIService.ExecQuery _
            ("Select * From Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
        For Each objItem In colItems
            If IsArray(objItem.IPAddress) Then
                strIP = objItem.IPAddress(0)
                strIP = ""
            End If
            If strIP <> "" Then
                objReport.WriteLine strComputer & "," & Chr(34) & strOSName & _
                    Chr(34) & "," & strOSVer & "," & strIP
            End If
        objReport.WriteLine strComputer & ",Did not respond"
    End If
WScript.Echo "Query complete."
Function PingCheck(strTarget, strPings, intPause)
    Const ForReading = 1
    Set objShell = CreateObject("WScript.Shell")
    strTempDir = objShell.ExpandEnvironmentStrings("%temp%")
    strTempFile = strTempDir & "\script-" & strTarget & ".txt"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objShell.Run "%comspec% /c ping -n " & strPings & " -w 100 " & _
        strTarget & ">" & strTempFile, 0, True
    WScript.Sleep intPause
    objShell.Run "%comspec% /c ping -n " & strPings & " -w 100 " & _
        strTarget & ">>" & strTempFile, 0, True
    Set objTempFile = objFSO.OpenTextFile(strTempFile, ForReading)
    strOutput = objTempFile.ReadAll
    objFSO.DeleteFile strTempFile, True
    If InStr(strOutput, "bytes=32") > 0 Then
        PingCheck = True
        PingCheck = False
    End If
End Function

Open in new window

johnnyjonathanAuthor Commented:
thanks Shift-3, works great!
is there anyway to make arrComputers read from a list of csv\txt since it's over 200 machines?
johnnyjonathanAuthor Commented:
complete, accurate AND easy to understand. thank you
johnnyjonathanAuthor Commented:
Also, sorry but i think i found an error, when trying to search for more then one machine, it brings the same results to all machines as to the first one?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now