Comment on Checking for USB Devices

Both work … Get-WmiObject -Class Win32_PnpEntity | Select-Object -ExpandProperty Caption Get-CimInstance -ClassName Win32_PnpEntity | Select-Object -ExpandProperty Caption WMI over CIM in most cases is habit or on PSv2 and below where CIM Does not exist. Folks are just far more use to WMI and CIM is only really a thing for the more recent OS Windows versions. Well, even if you are using the latest OS and PS version. You must always plan for the lowest common denominator in your enterprise. So, get in the habit, for now of using branching code. Meaning always check for OS and PS version and take the most prudent branch. However, for PSv6 (PSCore cross platform) only CIM works, as there Get-WMI* is not in PSCore. I still find much WMI far more performant that CIM and on many things (not in this simple case), and in many cases WMI brings back more than CIM. Odd, I know but it is what it is. The primary reason for CIM over WMI is WMI(DCOM) is not firewall friendly, well that and it’s where things are in PSCore cross platform. The primary reason for WMI is backwards compatibility. ‚blogs.technet.microsoft.com/heyscriptingguy/2014/01/27/what-is-cim-and-why-should-i-use-it-in-powershell’ ‚blogs.technet.microsoft.com/heyscriptingguy/2016/02/08/should-i-use-cim-or-wmi-with-windows-powershell’ ‚powershell.org/2013/03/24/wmi-vs-cim’ ‚maikkoster.com/cim-vs-wmi-cmdlets-the-top-reasons-i-changed’ ‚maikkoster.com/cim-vs-wmi-cmdlets-speed-comparison ‚informit.com/articles/article.aspx?p=2477536’

GD Star Rating
loading...