About CIM modules

Last week I made a private demo about how to discover CIM based modules.

At first, I did:

Get-Module -ListAvailable | 
Where ModuleType -eq 'CIM'

Based on what’s installed on a workstation or if it’s on a server, either there’s 0 result or the following:

…and that’s not what I really expected and wanted to illustrate.

I wanted actually to show how Microsoft has extended the number of cmdlets using CDXML (cmdlet definition XML).

If I do the following:

Get-NetAdapter | Get-Member

I can see the Get-NetAdapter cmldet returned a CIM instance of the ROOT/StandardCimv2/MSFT_NetAdapter class.

Now, if I query the type of module the Get-NetAdapter cmdlet comes from

Get-Command -Name Get-NetAdapter
Get-Module -Name NetAdapter

It’s clear that the NetAdapter module uses a manifest module type instead of CIM based type.

If I continue and show more properties of this NetAdapter module,

Get-Module -Name NetAdapter | Format-List

Nothing really relevant is shown except the fact that this module has nested modules.

Let’s investigate that NestedModules property:

Get-Module -Name NetAdapter | 
Select -Expand NestedModules


Using the ExpandProperty parameter reveals what I was looking for: the CIM module type.

Using a loop, I can now list the modules that have at least 1 CIM based nested module

Get-Module -ListAvailable | 
ForEach-Object { 
 if ('CIM' -in $_.NestedModules.ModuleType) { 
  $_ 
 }
}

After that I can do some calculation:

# How many modules have at least 1 CIM based nested module?
Get-Module -ListAvailable | 
ForEach-Object { 
 if ('CIM' -in $_.NestedModules.ModuleType) { 
  $_ 
 }
} | Measure

# How many cmdlets were added using these "CIM" modules
Get-Module -ListAvailable |
ForEach-Object { 
 if ('CIM' -in $_.NestedModules.ModuleType) {
  Get-Command -Module $_.Name 
 }
} | Measure

# Over a total of how many cmdlets, regardless modules types?
Get-Command | Measure

1 thought on “About CIM modules

  1. Pingback: Dew Drop - March 29, 2018 (#2694) - Morning Dew

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.