Dealing with CIM properties that are integer arrays

Saw a post about WmiMonitorID that intrigued me

If you use the WmiMonitorID:

PS> Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorID | select -f 1

Active                 : True
InstanceName           : DISPLAY\GSM598F\4&19086f00&0&UID200195_0
ManufacturerName       : {71, 83, 77, 0…}
ProductCodeID          : {53, 57, 56, 70…}
SerialNumberID         : {51, 48, 52, 78…}
UserFriendlyName       : {50, 50, 69, 65…}
UserFriendlyNameLength : 13
WeekOfManufacture      : 4
YearOfManufacture      : 2013
PSComputerName         :

You get a number of properties returned as an array of numbers. if you look at the property with Get-CimClass they unsigned 16 bit integers

Name               : ManufacturerName
Value              :
CimType            : UInt16Array
Flags              : Property, ReadOnly, NullValue
Qualifiers         : {MAX, read, WmiDataId}
ReferenceClassName :

Probably the easiest way to deal with them is a very simple function and calculated fields

function Convert-ArrayToName {
param ($array)

($array | foreach { [char][byte]$_} ) -join ”

}

Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorID |
select Active,
@{N=’Manufacturer’; E={Convert-ArrayToName -array $_.ManufacturerName }},
@{N=’ProductCode’; E={Convert-ArrayToName -array $_.ProductCodeID}},
@{N=’SerialNumber’; E={Convert-ArrayToName -array $_.SerialNumberID}},
@{N=’UserFriendlyName’; E={Convert-ArrayToName -array $_.UserFriendlyName}},
WeekOfManufacture,YearOfManufacture

 

The function Convert-ArrayToName accepts an array.  Using foreach-object the integers are converted to bytes and then to chars. Join the resultant array of chars and you get the string versions of the property

Call the function in a calculated field to convert the numeric array to a string – repeat for all relevant properties. You could create an object rather than just using select if you wish

Run the code and

Active                 : True
InstanceName           : DISPLAY\GSM598F\4&19086f00&0&UID200195_0
ManufacturerName       : {71, 83, 77, 0…}
ProductCodeID          : {53, 57, 56, 70…}
SerialNumberID         : {51, 48, 52, 78…}
UserFriendlyName       : {50, 50, 69, 65…}
UserFriendlyNameLength : 13
WeekOfManufacture      : 4
YearOfManufacture      : 2013
PSComputerName         :

Active                 : True
InstanceName           : DISPLAY\SEC3242\4&19086f00&0&UID265988_0
ManufacturerName       : {83, 69, 67, 0…}
ProductCodeID          : {51, 50, 52, 50…}
SerialNumberID         : {48, 0, 0, 0…}
UserFriendlyName       :
UserFriendlyNameLength : 0
WeekOfManufacture      : 0
YearOfManufacture      : 2012
PSComputerName         :

becomes

Active            : True
Manufacturer      : GSM            
ProductCode       : 598F           
SerialNumber      : 304NDJX51788   
UserFriendlyName  : 22EA63      
WeekOfManufacture : 4
YearOfManufacture : 2013

Active            : True
Manufacturer      : SEC            
ProductCode       : 3242           
SerialNumber      : 0              
UserFriendlyName  : 
WeekOfManufacture : 0
YearOfManufacture : 2012

This entry was posted in PowerShell and CIM, PowerShell and WMI. Bookmark the permalink.

Leave a comment