Solved

WMIC Script

Posted on 2016-07-22
1
27 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
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). …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

730 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