Sign in to follow this  
Followers 0
HolmesShelock

Error in retrieving 'HardwareID' field from WMI query

3 posts in this topic

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]

Share this post


Link to post
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]

Share this post


Link to post
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
Sign in to follow this  
Followers 0