Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-Products replaced with faster and better version #126

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

exp0se
Copy link
Contributor

@exp0se exp0se commented Aug 15, 2015

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

@jt-msft
Copy link
Collaborator

jt-msft commented Aug 17, 2015

This does not produce an equivalent output.

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

@exp0se
Copy link
Contributor Author

exp0se commented Aug 18, 2015

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

@jvaldezjr1
Copy link
Contributor

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

@exp0se
Copy link
Contributor Author

exp0se commented Aug 19, 2015

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?

@jvaldezjr1
Copy link
Contributor

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

@davehull
Copy link
Owner

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.

@jvaldezjr1
Copy link
Contributor

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
Copy link
Contributor

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.

@davehull
Copy link
Owner

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
#126 (comment).

@ghost
Copy link

ghost commented Sep 13, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants