Getting Properties of All Win32_* WMI Objects in PowerShell

I ran across the need today to display all the properties of each Win32_* WMI object.  To cut to the chase, this is what worked (thanks to /\/\o\/\/) for a bit of help simplifying this:
 
gwmi -list | where {$_.__class -match "Win32"} |
    select @{n=’WmiName’;e={$_.name}} , 
           @{n=’Properties’;e={$_.psbase.properties}} |
    select WmiName -expand Properties | 
    format-table Name,Type -groupby WmiName
 
This results in output like this:
 
   WmiName: Win32_ComputerSystemEvent
Name                  Type
—-                  —-
MachineName         String
SECURITY_DESCRIPTOR  UInt8
TIME_CREATED        UInt64
   WmiName: Win32_ComputerShutdownEvent
Name                  Type
—-                  —-
MachineName         String
SECURITY_DESCRIPTOR  UInt8
TIME_CREATED        UInt64
Type                UInt32
   WmiName: Win32_SystemTrace
Name                  Type
—-                  —-
SECURITY_DESCRIPTOR  UInt8
TIME_CREATED        UInt64

The one basic trick here is that you need to access the raw ManagementClass object via the "psbase" property in order to access the "Properties" property.  The PSBase property is available on all .NET objects within PowerShell because PowerShell adapts all .NET objects to PowerShell by creating a wrapper object around the .NET object.
Advertisements
This entry was posted in PowerShell. 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