PowerShell 3.0 CIM and WMI

Windows CIM in PowerShell

This article is designed for PowerShell beginners who are interested to learn about practical similarities and differences between CIM in PowerShell 3.0 and WMI in PowerShell 2.0.

My mission is to provide concrete examples to illustrate CIM and WMI.

PowerShell 3.0 CIM

 ♦

PowerShell 3.0 CIM FamilyWindows PowerShell 3.0

# PowerShell 3.0 script to enumerate CIM cmdlets.

Get-Command -Noun cim* | Format-Table Name

Result: Here is the list of Cim cmdlets

Export-CimCommand
Get-CimAssociatedInstance
Get-CimClass
Get-CimInstance
Get-CimSession
Invoke-CimMethod
New-CimInstance
New-CimSession
New-CimSessionOption
Register-CimIndicationEvent
Remove-CimInstance
Remove-CimSession
Set-CimInstance

Get-CIM Example

# PowerShell 3.0 CIM Example.
Get-CimInstance –ClassName Win32_ComputerSystem

A reminder that even this command accepts Get-Help, thus you could try:
Get-Help Get-Member -full. My point is that help will reveal other options, for example -MemberType Method.

Note 1:  You could filter Get-WmiObject win32_service by appending this command:
| Where {$_.name -NotMatch "__"}

Note 2:  The above script incorporates a filter.  Talking of filters, my friend ‘Mad’ Mick says that
 -filter "state = ‘running’" is superior to | Where {$_.state -eq "Running"} ` Do you know, I think Mick is right, -filter is better than where-object in this case.

New PowerShell 3.0 Cmdlets

PowerShell v3 brings dozens, hundreds, perhaps even thousands of new ‘cmdlets’.  However, researching with Get-Command, many seem to be functions.

Compare these two pieces of research.

Write-Host "Functions "(Get-Command -CommandType function).count
Write-Host "Cmdlets "(Get-Command -CommandType cmdlet).count

If you inspect these functions, they look like cmdlets, for example Get-NetIPAddress.  They act like cmdlets in that they have parameters, properties and methods.  For beginners to all intents an purposes they are cmdlets!

Yet, there remains a nagging doubt that one should understand more about CIM.  I want to reassured beginners that they don’t need to worry about the technical specifications of CIM MOFs before they can start creating useful scripts.

CIM Functions Are Easy to Use

The whole point of CIM functions is that they makes life easier for beginners, especially when the alternative is grappling with Get-WMIObject classes.  These CIM functions also extend what you can do in PowerShell, for example, with just one command in PowerShell v3 you can now Rename-Computer.

The only problem for a beginner is overthink.  You have spent time in mastering a medium difficult WMI technique; and now the arrival of CIM functions sounds like something even more difficult than GWMI.  Please remember they make it easier to achieve computer tasks, moreover these new CIM functions give you less to worry about provided you don’t get into philosophical debates about cmdlets v CIM functions.

Guy Recommends:  A Free Trial of the Network Performance Monitor (NPM)Review of Orion NPM v11.5 v11.5

SolarWinds’ Network Performance Monitor will help you discover what’s happening on your network.  This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

What I like best is the way NPM suggests solutions to network problems.  Its also has the ability to monitor the health of individual VMware virtual machines.  If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.

Download a free trial of Solarwinds’ Network Performance Monitor

CIM -versus- WMI

Remember that the ‘W’ in WMI stands for Windows, thus its Microsoft proprietry, whereas CIM is independent of software or hardware vendors. If you already have any experience of WMI, then relax CIM is just a superset, the big daddy of WMI. 

Take computer disks, both CIM and WMI provide handles for interogating the disk size and other properties.  Furthermore both CIM and WMI provide methods for ‘Setting’ values, for example IP Address.

Range of Devices Under the CIM Umbrella

My purpose here is to highlight the range of computer related components that CIM provide a schema, specification or Managed Object Format (MOF) code.

Alarm, Battery, BIOS, Chassis, Chip, LogicalDisk, Memory, PhysicalMemory, PhysicalDisk, Network Adapter, Video, USB.

Actual MOF Example for: Class CIM_NetworkAdapter

class CIM_NetworkAdapter : CIM_LogicalDevice
{
boolean AutoSense;
uint16 Availability;
string Caption;
uint32 ConfigManagerErrorCode;
boolean ConfigManagerUserConfig;
string CreationClassName;
string Description;
string DeviceID;
boolean ErrorCleared;
string ErrorDescription;
datetime InstallDate;
uint32 LastErrorCode;
uint64 MaxSpeed;
string Name;
string NetworkAddresses[];
string PermanentAddress;
string PNPDeviceID;
uint16 PowerManagementCapabilities[];
boolean PowerManagementSupported;
uint64 Speed;
string Status;
uint16 StatusInfo;
string SystemCreationClassName;
string SystemName;
};

Conclusion: I cannot think of a computer component that does not have a CIM description or MOF.  Message

Engineer's Toolset v10Guy Recommends: SolarWinds Engineer’s Toolset v10

This Engineer’s Toolset v10 provides a comprehensive console of 50 utilities for troubleshooting computer problems.  Guy says it helps me monitor what’s occurring on the network, and each tool teaches me more about how the underlying system operates.

There are so many good gadgets; it’s like having free rein of a sweetshop.  Thankfully the utilities are displayed logically: monitoring, network discovery, diagnostic, and Cisco tools.  Try the SolarWinds Engineer’s Toolset now!

Download your fully functional trial copy of the Engineer’s Toolset v10

GUID Hierarchy and Classes

CIM has GUIDs (Globally Unique Identifies), in this respect CIM reminds me of SNMP where you can manipulate devices via strings such as: 1.3.6.1.4.1.647.10893.1.20.5.  GUIDs reflect or enable the hierarchical nature of CIM, (WMI) and SNMP. 

Class: Top Level e.g. NetworkAdapter Above:
Relationships: Set of Attributes
Properties: Individual Attribute

Each class has a unique GUID

What’s New In PowerShell 3.0

 and to facilitate old hands in working that bit slicker.  What’s new in PowerShell 3.0 »

Windows CIM in PowerShell

This article is designed for PowerShell beginners who are interested to learn about practical similarities and differences between CIM in PowerShell 3.0 and WMI in PowerShell 2.0.

If you like this page then please share it with your friends

 


See more Windows PowerShell sections

PowerShell Home   • Introduction  • Dreams   • 3 Key Commands   • Free Permissions Analyzer

PowerShell Real-life Examples   • PowerShell Techniques   • PowerShell Syntax   • Contact

PowerShell ISE  • PowerShell 2.0   • PowerShell v 3.0   • PowerShell v 4.0   • PowerShell v 4.0

Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.