Script to export OS type and machine IP's

Hi,
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?
johnnyjonathanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shift-3Commented:
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)
        Next
        
        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)
            Else
                strIP = ""
            End If
        
            If strIP <> "0.0.0.0" Then
                objReport.WriteLine strComputer & "," & Chr(34) & strOSName & _
                    Chr(34) & "," & strOSVer & "," & strIP
            End If
        Next
    Else
        objReport.WriteLine strComputer & ",Did not respond"
    End If
Next
 
objReport.Close
 
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
    objTempFile.Close
    objFSO.DeleteFile strTempFile, True
 
    If InStr(strOutput, "bytes=32") > 0 Then
        PingCheck = True
    Else
        PingCheck = False
    End If
End Function

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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?
0
johnnyjonathanAuthor Commented:
complete, accurate AND easy to understand. thank you
0
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?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.