Kansa icon indicating copy to clipboard operation
Kansa copied to clipboard

Get-Products replaced with faster and better version

Open exp0se opened this issue 9 years ago • 10 comments

WMI is too slow, it is showing only MSI installed packages and it is dangerous to use because it runs consistency check and package repair when you query it. Don't use it. http://blogs.technet.com/b/heyscriptingguy/archive/2011/11/13/use-powershell-to-quickly-find-installed-software.aspx

exp0se avatar Aug 15 '15 12:08 exp0se

This does not produce an equivalent output.

PS > (gwmi Win32_Product).Count
320
PS > (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*).Count
124

jt-msft avatar Aug 17 '15 18:08 jt-msft

Thats because on 64 bit there is actually two keys. Forgot about that. I fixed it now. Plus you counting it wrong:

$a = Get-WmiObject Win32_Product | select -ExpandProperty Name
$a.Count
65
$c = Get-ItemProperty 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
| select -ExpandProperty DisplayName -ErrorAction SilentlyContinue
$c += Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*' | select -ExpandProperty DisplayName -ErrorAction SilentlyContinue
$c.Count
134

exp0se avatar Aug 18 '15 08:08 exp0se

I'm not getting anything close to consistent equivalent output either. Tested on Windows 7, PS4: This image is # of installed programs according to the Control Panel Programs and Features: screen shot 2015-08-18 at 3 38 27 pm

Running the above code from @exp0se:

$a = Get-WmiObject -Class Win32_Product | Select -ExpandProperty Name
$a.Count
292

$a = Get-WmiObject -Class Win32_Product
$a.Count
292

$b = Get-ItemProperty 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' 
| select -ExpandProperty DisplayName -ErrorAction SilentlyContinue
$b += Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*' 
| select -ExpandProperty DisplayName -ErrorAction SilentlyContinue
$b.count
532

jvaldezjr1 avatar Aug 18 '15 21:08 jvaldezjr1

Well, they are not going to be consistent because Win32_Product doesn't list everything installed, only stuff installed via Windows Installer. On my box it missed more than half of the programs that actually installed. Thats why i made a change - it just doesn't show everything, so why bother with it?

exp0se avatar Aug 19 '15 07:08 exp0se

Do these keys report on installed "Universal" apps as well, or just desktop versions? This would apply to Windows 8/2012/10 OSes.

jvaldezjr1 avatar Aug 19 '15 17:08 jvaldezjr1

The current Get-Products.ps1 collector says in the .SYNOPSIS that it only covers products installed via Windows Installer. I like this change that you've submitted. I'm curious why not all of the objects have a DisplayName field. I want to dig into this a bit more before committing the change. Thanks for the contribution.

davehull avatar Aug 19 '15 17:08 davehull

I manually looked through the sub keys to explain blanks also, and some subkeys don't have all the fields we would expect to see (AddressBook, ConnectionManager). screen shot 2015-08-19 at 12 15 23 pm The subkeys with GUIDs do. I also found another article here: https://social.msdn.microsoft.com/forums/en-US/94c2f14d-c45e-4b55-9ba0-eb091bac1035/c-get-installed-programs that mentioned searching HK CurrentUser as well (HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall*). That probably won't exist on servers as much as on end user workstations, so maybe testing to see if it exists is a better approach.

I expanded on the properties (and used Out-GridView 'ogv') to look at the results. There may be some cool analysis things that can be done with this, and maybe just toss out or supress the blanks for now?

Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*' | Select DisplayName, DisplayVersion, Publisher, InstallDate, HelpLink, UninstallString | ogv
screen shot 2015-08-19 at 12 25 02 pm Thanks for pointing out these keys and taking an interest in Kansa.

jvaldezjr1 avatar Aug 19 '15 18:08 jvaldezjr1

If you add PSPath to the select statement, you will see the subkey associated with the objects that appear to be blank. More research than anything.

jvaldezjr1 avatar Aug 19 '15 18:08 jvaldezjr1

I replied via GitHub, but I don't think it went out via email. I'm definitely liking this update, however, I think I'll rename the existing Get-Products.ps1 to Get-ProductsWMI.ps1 and call this one Get-ProductsReg.ps1. I'm going to play around with it a bit before committing it to the repo, but it will be committed, thank you for the contribution.

On Wed, Aug 19, 2015 at 11:31 AM, Juan Romero [email protected] wrote:

I manually looked through the sub keys to explain blanks also, and some subkeys don't have all the fields we would expect to see (AddressBook, ConnectionManager). [image: screen shot 2015-08-19 at 12 15 23 pm] https://cloud.githubusercontent.com/assets/7658588/9364944/10588b18-466c-11e5-813b-51c4caca981b.png The subkeys with GUIDs do. I also found another article here: https://social.msdn.microsoft.com/forums/en-US/94c2f14d-c45e-4b55-9ba0-eb091bac1035/c-get-installed-programs that mentioned searching HK CurrentUser as well (HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall*). That probably won't exist on servers as much as on end user workstations, so maybe testing to see if it exists is a better approach.

I expanded on the properties (and used Out-GridView 'ogv') to look at the results. There may be some cool analysis things that can be done with this, and maybe just toss out or supress the blanks for now?

Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall*' | Select DisplayName, DisplayVersion, Publisher, InstallDate, HelpLink, UninstallString | ogv

[image: screen shot 2015-08-19 at 12 25 02 pm] https://cloud.githubusercontent.com/assets/7658588/9365253/cd65ea60-466d-11e5-877e-8fc906041c6e.png Thanks for pointing out these keys and taking an interest in Kansa.

— Reply to this email directly or view it on GitHub https://github.com/davehull/Kansa/pull/126#issuecomment-132734156.

davehull avatar Aug 19 '15 22:08 davehull

What is the progress status of this feature? Does it require additional work? I am in need of a similar feature. If it does let me know.

ghost avatar Sep 13 '20 18:09 ghost