Jump to content

Need to narrow WMI query output


Bodman
 Share

Recommended Posts

Hi All, I have generated a WMI query using scriptomatic, but im trying to only output the information after the Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="USB\\VID_152D&PID_2338\\

So Basically I want to run my script and all to appear is the answer D57CA7226232

Any help greatly appreciated, I've gone around and around trying to solve this

AccessState:

Antecedent: \\COMPUTER\root\cimv2:Win32_USBController.DeviceID="PCI\\VEN_8086&DEV_283A&SUBSYS_101017AA&REV_02\\3&18D45AA6&0&D7"

Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="USB\\VID_152D&PID_2338\\D57CA7226232"

NegotiatedDataWidth:

NegotiatedSpeed:

NumberOfHardResets:

NumberOfSoftResets

; Generated by AutoIt Scriptomatic
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"
$Output=""
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_USBControllerDevice", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) then
   For $objItem In $colItems
       $Output = $Output & "Dependent: " & $objItem.Dependent & @CRLF
      if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
      $Output=""
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_USBControllerDevice" )
Endif

Thanks

Bod

Link to comment
Share on other sites

Can we assume that what you want always follows the last backslash? If so...

; Generated by AutoIt Scriptomatic
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"
$Output=""
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_USBControllerDevice", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) then
  For $objItem In $colItems
    $Output = StringTrimRight($objItem.Dependent, 1) ; trim trailing quote
    $Output = "Dependent: " & StringTrimLeft($Output, StringInStr($Output, "\", 2, -1)) & @CRLF
    Msgbox(1,"WMI Output",$Output)
  Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_USBControllerDevice" )
Endif
Edited by Spiff59
Link to comment
Share on other sites

Thanks for that, the script actually outputs the whole of the USBControllerDevice (22 lines see below) but I only want the information for 1 device (Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="USB\\VID_152D&PID_2338\\ ) Any idea how I can limit it to that.

Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="USB\\ROOT_HUB\\4&34787A46&0"

Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="USB\\ROOT_HUB\\4&1F0931D3&0"

Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="USB\\ROOT_HUB\\4&157829D5&0"

Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="USB\\ROOT_HUB\\4&2E050B29&0"

Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="USB\\ROOT_HUB\\4&9BB4E4F&0"

Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="USB\\ROOT_HUB20\\4&1FA45A99&0"

Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="USB\\VID_0424&PID_2524\\5&2B86C837&0&3"

Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="USB\\VID_050D&PID_3201\\6&2A72F29A&0&1"

Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="HID\\VID_050D&PID_3201&COL01\\7&1576BE94&0&0000"

Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="HID\\VID_050D&PID_3201&COL02\\7&1576BE94&0&0001"

Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="USB\\VID_045E&PID_0040\\6&2A72F29A&0&4"

Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="HID\\VID_045E&PID_0040\\7&3DA0528&0&0000"

Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="USB\\VID_045E&PID_00B0\\6&2A72F29A&0&3"

Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="USB\\VID_045E&PID_00B0&MI_00\\7&1F5C99AB&0&0000"

Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="HID\\VID_045E&PID_00B0&MI_00\\8&ADDDB07&0&0000"

Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="USB\\VID_045E&PID_00B0&MI_01\\7&1F5C99AB&0&0001"

Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="HID\\VID_045E&PID_00B0&MI_01&COL01\\8&22A1674C&0&0000"

Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="HID\\VID_045E&PID_00B0&MI_01&COL02\\8&22A1674C&0&0001"

Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="USB\\VID_13B1&PID_0023\\5&2B86C837&0&4"

Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="{5D624F94-8850-40C3-A3FA-A4FD2080BAF3}\\VWIFIMP\\6&1DBA515D&0&02"

Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="USB\\ROOT_HUB20\\4&88316C0&0"

Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="USB\\VID_0000&PID_0000\\5&2931F589&0&4"

Thanks in advance

Bod

Link to comment
Share on other sites

Thanks for that, the script actually outputs the whole of the USBControllerDevice (22 lines see below) but I only want the information for 1 device (Dependent: \\COMPUTER\root\cimv2:Win32_PnPEntity.DeviceID="USB\\VID_152D&PID_2338\\ ) Any idea how I can limit it to that.

I thought it should be something like this

$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_USBControllerDevice WHERE Dependent LIKE '%VID_152D&PID_2338%' ", "WQL", ...

But when I try to run this it returns nothing, so maybe there is needed some tweaking ...

Link to comment
Share on other sites

I thought it should be something like this

$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_USBControllerDevice WHERE Dependent LIKE '%VID_152D&PID_2338%' ", "WQL", ...

But when I try to run this it returns nothing, so maybe there is needed some tweaking ...

Ive tried every permutation of this that I can and unfortunately I still cant get any output although it definitely seems on the right tracks

Link to comment
Share on other sites

I thought it should be something like this

$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_USBControllerDevice WHERE Dependent LIKE '%VID_152D&PID_2338%' ", "WQL", ...

But when I try to run this it returns nothing, so maybe there is needed some tweaking ...

According to MSDN

http://msdn.microsoft.com/en-us/library/windows/desktop/aa394505(v=vs.85).aspx

Dependent property is not type string but Reference to the CIM_LogicalDevice instance.

That's why WHERE + LIKE doesn't work.

Edited by Zedna
Link to comment
Share on other sites

Thanks, I actually got it working by using a different WMI Class

SELECT * FROM Win32_PnPEntity WHERE DeviceID LIKE '%VID_152D&PID_2338%'

But I have found that when I run it on some of our computers I just get the answer D57CA7226232 but on others I get 2 answers D57CA7226232 and blank (Empty Message box)

This is because on those clients I have VID_152D&PID_2338 and also VID_152D&PID_2338&MI_00

how do I ignore the null value or the data from VID_152D&PID_2338&MI_00. I have tried NOT LIKE in the Query, but it dosnt like that :D

; Generated by AutoIt Scriptomatic
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"
$Output=""
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity WHERE DeviceID LIKE '%VID_152D&PID_2338%' ", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
body()
func body()
If IsObj($colItems) then
  For $objItem In $colItems
   ConsoleWrite ($Output)$Output = StringTrimRight($objItem.DeviceID, 1) ; trim trailing quote
    $Output = "" & StringTrimLeft($Output, StringInStr($Output, "\", 2, -1)) & @CRLF

Msgbox(1,"WMI Output",$Output)
 Next 
Endif
endfunc
Link to comment
Share on other sites

Thanks, I actually got it working by using a different WMI Class

But I have found that when I run it on some of our computers I just get the answer D57CA7226232 but on others I get 2 answers D57CA7226232 and blank (Empty Message box)

This is because on those clients I have VID_152D&PID_2338 and also VID_152D&PID_2338&MI_00

how do I ignore the null value or the data from VID_152D&PID_2338&MI_00. I have tried NOT LIKE in the Query, but it dosnt like that :D

escape the backslash after VID_152D&PID_2338 with a backslash

$colItems = $objWMIService.ExecQuery("SELECT DeviceID FROM Win32_PnPEntity WHERE DeviceID LIKE '%VID_152D&PID_2338\\%' ", "WQL", _

I see fascists...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...