Solved

WMIC Script

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

Technology Partners: 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

Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
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.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 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