Writable properties for a WMI class

Do you know how to discover which properties on a WMI class, and therefore a WMI instance, can be modified?

Get-CimClass from the PowerShell 3.0 CIM cmdlets is the answer:

$class = Get-CimClass -ClassName win32_volume

$class.CimClassProperties

 

The last command returns all of the properties in this format

 

Name               : Description
Value              :
CimType            : String
Flags              : Property, ReadOnly, NullValue
Qualifiers         : {read}
ReferenceClassName :

 

Name               : DriveLetter
Value              :
CimType            : String
Flags              : Property, NullValue
Qualifiers         : {read, write}
ReferenceClassName :

 

Notice the first one has a Flag of ReadOnly and the second one has a Qualifier of write. So the question becomes how can you filter on those two items?

 

If you run something like this:

$class = Get-CimClass -ClassName Win32_Volume
$class.CimClassProperties |
foreach {
if ($psitem | select -ExpandProperty Qualifiers | where Name -eq 'write'){$psitem}
if (($psitem.Flags -split ', ') -notcontains 'Readonly')  {$psitem}
}

 

You will see that some properties may not be Readonly but also aren’t writable such as:

Name               : NumberOfBlocks
Value              :
CimType            : UInt64
Flags              : Property, NullValue
Qualifiers         : {MappingStrings}
ReferenceClassName :

 

In that case we need just the writable properties

Get-CimClass -ClassName Win32_Volume  |
select -ExpandProperty CimClassProperties |
foreach {
if ($psitem | select -ExpandProperty Qualifiers | where Name -eq 'write'){$psitem}
}

 

This brings the results down to three properties DriveLetter,  IndexingEnabled,  Label

The first and last I expected – IndexEnabled was new to me

Leave a Reply