Cim or Wmi

This topic contains 2 replies, has 3 voices, and was last updated by Profile photo of Richard Siddaway Richard Siddaway 7 months, 4 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #34695
    Profile photo of Liam Kemp
    Liam Kemp
    Participant

    Should I use Get-CimInstance or Get-WmiObject?
    Using Visual Studio Code with the powershell extension – I get a warning when using Wmi that I should use Cim. But using Sapien Powershell Studio 2015 the intellesense stuff doesn't bring up the list of classes when I use Cim, but it does when I use Wmi, which makes it easier when i'm looking for what I want. I've also watched some fairly recent powershell videos on Lynda.com and pluralsight where Wmi is still being used.

    #34696
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    You should use Get-CimInstance if you can. It's not always feasible however. Get-CimInstance relies on WinRM. So if you do not have WinRM enabled in your environment, you have to stick with Get-WmiObject. Get-CimInstance is what MS is developing going forward. One of the beautify things about Get-CimInstance is that is strives to more heterogeneous usage, whereas Get-WmiObject is only usable against Windows Platforms.

    Here is a nice blog comparing the two.
    https://blogs.msdn.microsoft.com/powershell/2012/08/24/introduction-to-cim-cmdlets/

    #34701

    This deserves a longer answer so I'll put up a blog post on it. Short answer is that the CIM cmdlets are the preferred way forward. The WMI cmdlets are unlikely to be developed any further – in fact the Get-WmiObject help files states 'Starting in Windows PowerShell 3.0, this cmdlet has been superseded by Get-CimInstance.'

    As stated above the CIM cmdlets use WSMAN (you need the WinRM service running but you don't need to have enabled PowerShelll remoting – modern Windows server OSs have it enabled anyway) though can drop back to DCOM if needed. WMI cmdlets use DCOM

    The CIM cmdlets also unravel dates into a usable format

    Invoke-CimMethod uses a hash table for method parameters so avoids the order issue that Invoke-WmiMethod has.

    One draw back to the CIM cmdlets is that you can't access ammended data on the WMI class – but thats not something done frequently

    Get-CimClass is great for discovery. The ability to refresh an object is useful.

    I always recommend, and use, the CIM cmdlets these days. if you see material recommending the WMI cmdlets contact that author and suggest he brings his material up to date

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.