Best Practice: It is recommended to use CIM cmdlets, not WMI cmdlets.
Explanation:
WMI cmdlets are considered obsolete but if you stil use legacy PowerShell v1/2 you could use them.
Since Powershell v3 CIM new cmdlets are available.
1 2 3 4 5 6 7 |
WMI (Not recommended) (Get-WmiObject -ClassName win32_operatingsystem).LastBootUpTime 20150522095242.375199+120 CIM (Recommended) (Get-CimInstance -ClassName win32_operatingsystem).LastBootUpTime 22 May 2015 09:52:42 |
Microsoft is not spending 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 directly the correct Datetime format (no more conversion needed).