Jump to content

Error in retrieving 'HardwareID' field from WMI query


Go to solution Solved by jguinch,

Recommended Posts

My script goes like this:

$objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
$wmiQuery = "SELECT * FROM Win32_PnPEntity WHERE Name LIKE '%(COM%)'"
$comPorts = $objWMIService.ExecQuery($wmiQuery, "WQL", 0)
For $comPort in $comPorts
    ConsoleWrite("Name:" & $comPort.Name & ", HardwareID: " & $comPort.HardwareID & @CRLF)
Next

The output is this:

 

Name:Device Diagnostic Interface (COM11), HardwareID: 

Name:Device Application Interface (COM12), HardwareID: 
Name:Device Pipe (COM10), HardwareID: 

 

The result returned by the same query triggered by WMIExplorer is this

WMIQuery.png

As you can see. my code snippet can access 'Name' field but fails to retrieve the values for 'HardwareID' field. Where am I going wrong?

[size="2"][font="arial, verdana, tahoma, sans-serif"]ProtectData - A Data Protection software for floppies[/font][/size] [size="2"][hr][/size][size="2"]Sessionchange - A Windows service capable of tracking session change events[/size][size="2"][b][/b][/size]

Link to comment
Share on other sites

  • Solution

Look at the Win32_PnPEntity help page : the HardwareID flied is an array.

So try with this :

ConsoleWrite("Name:" & $Name & ", HardwareID: " & $HardwareID[0] & @CRLF)
Link to comment
Share on other sites

 

Look at the Win32_PnPEntity help page : the HardwareID flied is an array.

 

Thanks a lot. I completely missed this part.

[size="2"][font="arial, verdana, tahoma, sans-serif"]ProtectData - A Data Protection software for floppies[/font][/size] [size="2"][hr][/size][size="2"]Sessionchange - A Windows service capable of tracking session change events[/size][size="2"][b][/b][/size]

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...