• BGinfo WMI VBS Script

    Author
    Topic
    #473515

    Hi Everyone,

    I’m more sys-admin then I am programmer so here goes.

    Running BGinfo to put up system stats on servers (HP mostly) but also employing WMI queries as well.

    i.e. pull serial number & product number from WMI query in BGinfo,

    Code:
    SELECT SerialNumber FROM Win32_BIOS = AUB0441HMH

    GOOD!

    BUT

    Code:
    SELECT OEMStringArray FROM Win32_ComputerSystem
    Code:
    PSF:                                                             Product ID: AU663A

    BAD!

    The second query is what I am having trouble with because when displayed on screen it looks bad.

    Is there a way to tidy the output via vbs?

    Preferred result just like the first query for the serial:

    Code:
    SELECT OEMStringArray FROM Win32_ComputerSystem = AU663A

    This is my attempt and it displays the output to BGInfo but with the same tacky output which needs tidying up but I don’t have a clue how to do that part.

    Code:
    Dim objWMIService
    Dim colItems ‘Collection returned from the WMI query
    Dim objItem ‘Each item in the colItems
    Dim strResult 
    Const wbemFlagReturnImmediately = &h10
    Const wbemFlagForwardOnly = &h20
    
    ‘*** Connect to this server’s WMI Service
    Set objWMIService = GetObject(“winmgmts:\.rootCIMV2”)’Dot is local computer 
    ‘*** Query WMI
    Set colItems = objWMIService.ExecQuery(“SELECT OEMStringArray FROM Win32_ComputerSystem”, “WQL”, _
    wbemFlagReturnImmediately + wbemFlagForwardOnly) 
    For Each objItem In colItems
     strResult = Join(objItem.OEMStringArray, “,”)
    Next
    Echo strResult

    So do the brain-trust of Windows Secrets Lounge have any suggestions/solution(s)?

    Note: If this is not in the right section please move appropriately.

    Viewing 7 reply threads
    Author
    Replies
    • #1258268

      As a matter of courtesy, when cross-posting on different forums, it’s polite to add a link to the other thread(s): BGinfo WMI-VBS Script – Overclockers Australia Forums. This helps avoid people spending time on solved problems.

      When I run that script in Word (VBA), I just get “www.dell.com” back. (To test, change “Echo strResult” to “MsgBox strResult”.)

      Can you post some sample data that you need cleaned up? Modify data that is sensitive or confidential. For best results, put it in a .txt attachment to preserve the spacing.

    • #1258271
      Code:
      SELECT OEMStringArray FROM Win32_ComputerSystem
      Code:
      PSF:                                                             Product ID: AU663A

      BAD!

      I have quoted the output in the code box above. As you can see there there is a preceding PSF: Product ID: AU663A

      I would prefer if it would only output from Product ID: onwards i.e. AU663A

      Obviously results will vary due to it being machine specific output so I can understand this might be a bit tricky but I thought there might be a way to trim/cut the output.

      As a matter of courtesy, when cross-posting on different forums, it’s polite to add a link to the other thread(s)

      Noted jscher2000

    • #1258318

      Oh, I thought there would be a whole array of output. Since you want from the middle to the end of a single string, try using the Mid() function to start where you want, and the Trim() function to clean up any trailing space. Replace your Echo line with this:

      Code:
      Echo Trim(Mid(strResult, InStr(1, strResult, "Product ID")))

      I haven’t tested that with real data, but it should be reasonably close.

    • #1258398

      Hi jscher2000,

      Thanks for taking to the time to reply to this one and I have now tested it on a HP server to yield the new result which is:

      Code:
      ID: AU663A

      This is perfectly acceptable and I thank you for your input

    • #1258418

      Or

      Code:
      wscript.echo Trim(Mid(strResult, InStr(1, strResult, "Product ID") + 4))

      Adjust the number to get the desired result.

      Alternatively

      Code:
      arrResult = split(strResult, ":")
      wscript.echo Trim(arrResult(ubound(arrResult)))
      

      cheers, Paul

    • #1258419

      Don’t forget to tie down the BGinfo directory so no-one has write access. We don’t want injected start up scripts.

      cheers, Paul

    • #1258460

      Odd. The word Product should have appeared in the output. I wonder whether that string contains nulls or other characters that VB doesn’t really understand. (Those may have been converted to space when pasting into a post…)

    • #1258546

      Alternatively

      Code:
      arrResult = split(strResult, ":")
      echo Trim(arrResult(ubound(arrResult)))
      

      This code gave the perfect output. It’s a bit of niche requirement as I can’t cater for all servers but HP seem to have stored their Server Product ID’s in this string. It does exactly what I want for the time being so I thank you both.

      I’m sure they’ll change something in the next revision of Proliant servers

      Odd. The word Product should have appeared in the output. I wonder whether that string contains nulls or other characters that VB doesn’t really understand. (Those may have been converted to space when pasting into a post…)

      Sorry for the confusion. In my previous post I modified your code to only Output ID: xxx

      • #1367874

        Hello, I Recommend to you bginfo4x from http://bginfo4x.sourceforge.net
        You can use powershell scripts or shell scripts, and create a centralized hardware inventory withh the exports functions.
        It also has an alarm and script module (launcher), an has lots of features because is pretty configurable.
        Even more is multiplatform: windows, linux and Mac.

    Viewing 7 reply threads
    Reply To: BGinfo WMI VBS Script

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: