WMI integer properties – alternative decoding options


WMI has many properties where the the value is an integer:

£> Get-CimInstance -ClassName Win32_LogicalDisk | Format-Table DeviceId, DriveType, Size, FreeSpace -a

DeviceId DriveType         Size    FreeSpace
——– ———         —-    ———
C:               3 135810510848 120492625920
D:               5


In the example drive type 3 is a standard hard disk and drive type 5 is defined as a compact disk




Remembering these can be a pain – there are a couple of ways to decode these values.


You could use a hash table – I showed many examples of this in PowerShell and WMI – www.manning.com/siddaway2


$dtype = DATA {ConvertFRom-StringData -StringData @’
3 = Hard Drive
5 = Compact Disk
Get-CimInstance -ClassName Win32_LogicalDisk |
Format-Table DeviceId, DriveTYpe, @{N=’TYpe’; E={$dtype[“$($_.DriveType)”]}}, Size, FreeSpace –a



DeviceId DriveTYpe TYpe                 Size    FreeSpace
——– ——— —-                 —-    ———
C:               3 Hard Drive   135810510848 120495980544
D:               5 Compact Disk



Define the hash table via ConvertFrom-StringData . You can then just use the hash table as a look up to convert the numeric value of drive type into a descriptive name.

With WMF 5.0 and PowerShell classes there is another option


enum dtype {
HardDrive = 3
CompactDisk = 5

Get-CimInstance -ClassName Win32_LogicalDisk |
Format-Table DeviceId, DriveTYpe, @{N=’TYpe’; E={[dtype]$($_.DriveType)}}, Size, FreeSpace –a


DeviceId DriveTYpe        TYpe         Size    FreeSpace
——– ———        —-         —-    ———
C:               3   HardDrive 135810510848 120496607232
D:               5 CompactDisk


Create a enumeration using the enum keyword. The descriptive text CANNOT have spaces (delimited strings don’t work either). You can then substitute the enum value into your calculated field.

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s