February 1, 2016 at 10:06 pm #34695
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.
February 1, 2016 at 10:48 pm #34696
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.
February 2, 2016 at 1:17 am #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
You must be logged in to reply to this topic.