Solved

WMIC Script

Posted on 2016-07-22
1
19 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 13

Accepted Solution

by:
frankhelk earned 500 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now