Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to look at the schema of a WMI class. Microsoft Scripting Guy, Ed Wilson, is here. One of the cool things about WMI is that it is largely self-describing. This means that I can use WMI and look at WMI. With the CIM cmdlets, this goes even a step further. For example, if I want to look at the Win32_Desktop WMI class, I can use the Get-CimClass cmdlet, and examine it:
PS C:> Get-CimClass win32_desktop
NameSpace: ROOT/cimv2
CimClassName CimClassMethods CimClassProperties
———— ————— ——————
Win32_Desktop {} {Caption, Description,… From this output, I can see that the class appears in the Root/cimv2 WMI namespace. Not really a surprise because that is the default namespace. I can also see that there are no methods. This means that I will not be able to do much more than view information. I can drill down further to see the properties. To do this, I select and expand the cimClassProperties property. This is shown here:
Get-CimClass win32_desktop | select -ExpandProperty cimclassproperties The output, however, scrolls and scrolls because each property is more than a simple name. It contains qualifiers, flags, and more. Here is the output for the first couple of properties:
PS C:> Get-CimClass win32_desktop | select -ExpandProperty cimclassproperties
Name : Caption
Value :
CimType : String
Flags : Property, ReadOnly, NullValue
Qualifiers : {MaxLen, read}
ReferenceClassName :
Name : Description
Value :
CimType : String
Flags : Property, ReadOnly, NullValue
Qualifiers : {read}
ReferenceClassName : One of the things that is interesting is that the qualifiers are Read Only. Some properties are actually Read/Write; therefore, the class may not expose a method, but it still has updatable properties. I first look for all Read properties. This command and partial output are shown here:
PS C:> (Get-CimClass win32_desktop | select -ExpandProperty cimclassproperties).where({$psitem.qualifiers -match ‘read’})
Name : Caption
Value :
CimType : String
Flags : Property, ReadOnly, NullValue
Qualifiers : {MaxLen, read}
ReferenceClassName :
Name : Description
Value :
CimType : String
Flags : Property, ReadOnly, NullValue
Qualifiers : {read}
ReferenceClassName : Now, I want to see if there are any writable properties exposed via this class. Here is the command I use:
PS C:> (Get-CimClass win32_desktop | select -ExpandProperty cimclassproperties).where({$psitem.qualifiers -match ‘write’})
PS C:> Hmm…nothing comes back. Well, that was to be expected. I happen to know of a WMI class, Win32_ComputerSystem, that contains a few writable properties. So I test my command on that class. Here is the command and the results:
PS C:> (Get-CimClass win32_computersystem | select -ExpandProperty cimclassproperties).where({$psitem.qualifiers -match ‘write’})
Name : Roles
Value :
CimType : StringArray
Flags : Property, NullValue
Qualifiers : {read, write}
ReferenceClassName :
Name : AutomaticManagedPagefile
Value :
CimType : Boolean
Flags : Property, NullValue
Qualifiers : {MappingStrings, read, write}
ReferenceClassName :
Name : AutomaticResetBootOption
Value :
CimType : Boolean
Flags : Property, NullValue
Qualifiers : {MappingStrings, read, write}
ReferenceClassName :
Name : CurrentTimeZone
Value :
CimType : SInt16
Flags : Property, NullValue
Qualifiers : {MappingStrings, read, write}
ReferenceClassName :
Name : EnableDaylightSavingsTime
Value :
CimType : Boolean
Flags : Property, NullValue
Qualifiers : {write}
ReferenceClassName :
Name : SystemStartupDelay
Value :
CimType : UInt16
Flags : Property, NullValue
Qualifiers : {DEPRECATED, MappingStrings, Privileges, read…}
ReferenceClassName :
Name : SystemStartupOptions
Value :
CimType : StringArray
Flags : Property, NullValue
Qualifiers : {DEPRECATED, MappingStrings, Privileges, read…}
ReferenceClassName :
Name : SystemStartupSetting
Value :
CimType : UInt8
Flags : Property, NullValue
Qualifiers : {DEPRECATED, MappingStrings, Privileges, read…}
ReferenceClassName :
Name : Workgroup
Value :
CimType : String
Flags : Property, NullValue
Qualifiers : {MappingStrings, read, write}
ReferenceClassName : It seems that some of the properties are deprecated. This means that I am not supposed to use them. I wonder if I can find an easier way to see this information. I modify my command. This command is pretty long, and it is a single-line command that wrapped on the blog:
PS C:> (Get-CimClass win32_computersystem | select -ExpandProperty cimclassproperties).where({$psitem.qualifiers -match ‘write’ -and $psitem.qualifiers -match ‘deprecated’})
Name : SystemStartupDelay
Value :
CimType : UInt16
Flags : Property, NullValue
Qualifiers : {DEPRECATED, MappingStrings, Privileges, read…}
ReferenceClassName :
Name : SystemStartupOptions
Value :
CimType : StringArray
Flags : Property, NullValue
Qualifiers : {DEPRECATED, MappingStrings, Privileges, read…}
ReferenceClassName :
Name : SystemStartupSetting
Value :
CimType : UInt8
Flags : Property, NullValue
Qualifiers : {DEPRECATED, MappingStrings, Privileges, read…}
ReferenceClassName : It looks like the startup stuff is all deprecated. If I only want to look at the property names, I can choose it directly from my query. This is shown here:
PS C:> (Get-CimClass win32_desktop | select -ExpandProperty cimclassproperties).name
Caption
Description
SettingID
BorderWidth
CoolSwitch
CursorBlinkRate
DragFullWindows
GridGranularity
IconSpacing
IconTitleFaceName
IconTitleSize
IconTitleWrap
Name
Pattern
ScreenSaverActive
ScreenSaverExecutable
ScreenSaverSecure
ScreenSaverTimeout
Wallpaper
WallpaperStretched
WallpaperTiled Because I may not know what qualifiers a WMI class supports, I can easily use the Get-CimClass cmdlet to return those qualifiers:
PS C:> (Get-CimClass win32_process).CimClassQualifiers.name
Locale
UUID
CreateBy
DeleteBy
dynamic
provider
SupportsCreate
SupportsDelete
PS C:> (Get-CimClass win32_desktop).CimClassQualifiers.name
Locale
UUID
dynamic
Privileges
provider
PS C:> (Get-CimClass win32_Computersystem).CimClassQualifiers.name
Locale
UUID
dynamic
provider
SupportsUpdate Keep in mind that these are qualifiers on the WMI class itself, not qualifiers on the properties. I can obtain a list of all the qualifiers on all of the properties, sort them, and then get the unique qualifier names. This is shown here:
PS C:> (Get-CimClass win32_process | select -ExpandProperty cimclassproperties).qualifiers.name | sort | get-unique
CIM_Key
Fixed
key
MappingStrings
MaxLen
Override
Privileges
Propagated
read
ValueMap That is all there is to using Windows PowerShell to look at a WMI class schema. CIM Week will continue tomorrow when I will talk about more cool stuff. I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace. Ed Wilson, Microsoft Scripting Guy
0 comments