WMI is a powerful feature. Remember that WMI is CMI and CMI is WMI. In this blog post I am going to play with WMI Objects on the local computer and on remote computers. If you want to do an inventory of all installed software in your active directory domain, then keep on reading my post.
Get-WmiObject vs. Get-CimInstance
WMI and CIM is a definition of management information. Vendors use WMI to provide their informations. In this article we will concentrate on the class win32_product. The win32_product class provides information of all installed software. But there are differences between Get-WmiObject and Get-CimInstance.
The output is different. But it’s not the only variation.
Get-CimInstance enables you to browse all possible classes by pressing TAB or to type win32_ and press CTRL + Space. You get warned: “Are you sure you want to show all of them?” 😉 Yes, you are.
I think it’s better to proceed with Get-CimInstance.
Getting all installed software on the local host
As promised, we concentrate on gathering information of installed software. To do so, I recommend modifying the output. What are the most important informations and how to get them? Simply run Get-Member to explore all properties.
I’ve highlighted some of them which are in my view the most important ones. To get a better screen I send the output to Out-GridView.
Get-CimInstance win32_product | Select-Object Name, PackageName, InstallDate | Out-GridView
Nice. So we have a list of our currently installed software. Let’s go to the bigger challenge: To retrieve a list of software from remote computers.
Get installed Software from Remote Computers
Make sure WinRM is enabled on your computers. WinRM is enabled by default on Windows Server 2012/2016, but not on Client operating systems. More about enabling WinRM in this article:
Ok, my testing environment is very small. I only have 2 computers (server02 and client01). Let’s get the Computer Names from Active Directory from a specific OU and then run Get-CimInstance against them.
(Get-ADComputer -Filter * -Searchbase "OU=Test,DC=sid-500,DC=com").Name | Out-File C:\Temp\Computer.txt | notepad C:\Temp\Computer.txt
Review your list carefully. Now we call the shots. Here we go.
Get-CimInstance -ComputerName (Get-Content C:\Temp\Computer.txt) -ClassName win32_product -ErrorAction SilentlyContinue| Select-Object PSComputerName, Name, PackageName, InstallDate | Out-GridView
Have fun documenting your environment!