Powershell Best Practice #4: Use CIM cmdlet (not WMI cmdlet)

By | May 22, 2015

Best Practice: It is recommended to use CIM cmdlets, not WMI cmdlets.

Explanation: WMI cmdlets are considered as obsolete but if you need to use legacy PowerShell v1/2 so you need to use them, since Powershell v3 CIM new cmdlets are available.

Microsoft is not investigating time on WMI cmdlets, it means that no additional development or improvement is expected.
However, the positive point of WMI cmdlets is the backwards compatibility with older PowerShell versions.

CIM and WMI use the same WMI backend but the way of communication is different.

CIM cmdlets

  • DCOM : used when querying the local computer
  • WS-MAN : used for ad hoc connections to remote computer
  • DCOM or WS-MAN : used for session-based connections to remote computers

WMI cmdlets

  • Session-based connections not supported
  • Support only ad hoc connections over DCOM

A great benefit of CIM is the use of WSMAN (WS-Management) protocol for remote access.
Performing queries WMI using RPC/DCOM was not very firewall friendly, it is now easier using WSMAN protocol.
DCOM uses RPC and this protocol requires special firewall exceptions.

Microsoft has implemented the WS-Management standard in Windows Remote Management (WinRM).

Note: CIM tend to return direclty the correct Datetime format (no more conversion needed).


previous-buttonnext-button

2 thoughts on “Powershell Best Practice #4: Use CIM cmdlet (not WMI cmdlet)

  1. Pingback: Powershell Best Practice #5: Avoid the “Green Code” (not excessive and useless comments) | Powershell Guru

  2. Pingback: Powershell Best Practice #3: Use Write-Output (not Write-Host) | Powershell Guru

Leave a Reply

Your email address will not be published. Required fields are marked *