Results 1 to 10 of 10
  1. #1
    3 Star Lounger
    Join Date
    Dec 2009
    Location
    Sydney, Australia
    Posts
    254
    Thanks
    0
    Thanked 5 Times in 5 Posts
    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:\\.\root\CIMV2")'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.

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    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.

  3. #3
    3 Star Lounger
    Join Date
    Dec 2009
    Location
    Sydney, Australia
    Posts
    254
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by Josh B View Post
    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: <large space> 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.

    Quote Originally Posted by jscher2000 View Post
    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

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    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.

  5. #5
    3 Star Lounger
    Join Date
    Dec 2009
    Location
    Sydney, Australia
    Posts
    254
    Thanks
    0
    Thanked 5 Times in 5 Posts
    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

  6. #6
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,203
    Thanks
    49
    Thanked 987 Times in 917 Posts
    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

  7. #7
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,203
    Thanks
    49
    Thanked 987 Times in 917 Posts
    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

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    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...)

  9. #9
    3 Star Lounger
    Join Date
    Dec 2009
    Location
    Sydney, Australia
    Posts
    254
    Thanks
    0
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by P T View Post
    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

    Quote Originally Posted by jscher2000 View Post
    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

  10. #10
    New Lounger
    Join Date
    Jan 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •