Solved

WMIC Script

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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.

773 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