?
Solved

WMIC Script

Posted on 2016-07-22
1
Medium Priority
?
36 Views
Last Modified: 2016-07-25
I'm looking for a script that will use the WMIC command and scan an IP range and return the computer name,  model, serial number, processor type, processor speed, Ram and harddrive size.
0
Comment
Question by:Mwvarner
1 Comment
 
LVL 14

Accepted Solution

by:
frankhelk earned 2000 total points
ID: 41727135
Just ripped out from one of my Excel support workbook macro modules.

(Taylor to your needs as needed, use at your own risk, your mileage may vary ;-)

Public Function GetOS(ByVal node As String, ByVal user As String, ByVal pass As String) As String

    Dim line As String
    Dim part As Variant
    Dim Target As Range
    Dim i As Integer
    Dim First As Boolean
    Dim oExec As Object
    Dim oOutput As Object
    Dim oShell As Object
    Dim lines As Collection
    Dim sTemp As String
    Dim iTemp As Double
    Dim OSArch As Boolean
    
    OSArch = True
        
    Set lines = New Collection
    Set oShell = CreateObject("WScript.Shell")
    
    'run command'
    sTemp = "wmic /node:" + node + " /user:" + node + Chr(92) + user + " /password:" + pass + _
                            " os get caption,OSArchitecture,CSDVersion /format:csv"
    Set oExec = oShell.Exec(sTemp)
    
    Set oOutput = oExec.StdOut
    While oExec.Status = 0 ' WshRunning
        DoEvents
    Wend
    'OSArchitecture is not supported on all Windows OS, which might result in an error
    If oExec.ExitCode <> 0 Then
        OSArch = False
        Set oShell = CreateObject("WScript.Shell")
        sTemp = "wmic /node:" + node + " /user:" + node + Chr(92) + user + " /password:" + pass + _
                            " os get caption,CSDVersion /format:csv"
        Set oExec = oShell.Exec(sTemp)
        Set oOutput = oExec.StdOut
        While oExec.Status = 0 ' WshRunning
            DoEvents
        Wend
        DoEvents
        If oExec.ExitCode <> 0 Then
            Set oOutput = oExec.StdErr
            While Not oOutput.AtEndOfStream
                line = Trim(oOutput.ReadLine)
                line = Replace(line, Chr(13), "")
                If line <> "" Then
                    'Depends on your host language version; this is for german host
                    If InStr(1, line, "Beschreibung") > 0 Then
                        GetOS = "***" + Mid(line, InStr(1, line, "=") + 2) + "***"
                    End If
                End If
            Wend
            Exit Function
        End If
    End If
    
    DoEvents
    ' Ergebnisse verarbeiten
    First = True
    While Not oOutput.AtEndOfStream
        line = Trim(oOutput.ReadLine)
        line = Replace(line, Chr(13), "")
        If line <> "" Then
            If First Then
                First = False
            Else
                If OSArch Then
                    GetOS = Trim(Split(line, ",")(1)) + " " + Trim(Split(line, ",")(2)) + " " + Trim(Split(line, ",")(3))
                Else
                    GetOS = Trim(Split(line, ",")(1)) + " " + Trim(Split(line, ",")(2))
                End If
            End If
        End If
    Wend
    GetOS = Replace(GetOS, "(R)", "", VbCompareMethod.vbTextCompare)
    GetOS = Replace(GetOS, "©", "", VbCompareMethod.vbTextCompare)
    GetOS = Replace(GetOS, "Microsoft ", "", VbCompareMethod.vbTextCompare)
    GetOS = Replace(GetOS, "Enterprise ", "Ent ", VbCompareMethod.vbTextCompare)
    GetOS = Replace(GetOS, "Standard ", "Std ", VbCompareMethod.vbTextCompare)
    GetOS = Replace(GetOS, "Edition ", "", VbCompareMethod.vbTextCompare)
    GetOS = Replace(GetOS, "Windows ", "Win", VbCompareMethod.vbTextCompare)
    GetOS = Replace(GetOS, "Professional ", "Pro ", VbCompareMethod.vbTextCompare)
    GetOS = Replace(GetOS, "Professional", "Pro", VbCompareMethod.vbTextCompare)
    GetOS = Replace(GetOS, "Win2000 Server", "Win2k Srv ", VbCompareMethod.vbTextCompare)
    GetOS = Replace(GetOS, "WinServer 2003 ", "Win2k3 Srv ", VbCompareMethod.vbTextCompare)
    GetOS = Replace(GetOS, "WinServer 2008 ", "Win2k8 Srv", VbCompareMethod.vbTextCompare)
    GetOS = Replace(GetOS, "64-bit", "x64", VbCompareMethod.vbTextCompare)
    GetOS = Replace(GetOS, "32-bit", "x86", VbCompareMethod.vbTextCompare)
    GetOS = Replace(GetOS, "X64", "x64", VbCompareMethod.vbTextCompare)
    GetOS = Replace(GetOS, "Service Pack ", "SP", VbCompareMethod.vbTextCompare)
    GetOS = Replace(GetOS, "Service Pack", "SP", VbCompareMethod.vbTextCompare)
End Function

Open in new window


You'll need some outer macro to generate IP's and supply credentials, but basically that's it.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Unable to change the program that handles the scan event from a network attached Canon/Brother printer/scanner. This means you'll always have to choose which program handles this action, e.g. ControlCenter4 (in the case of a Brother).
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Suggested Courses

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question