How do I do get-itemproperty with an added SPECIFIC-WORD filter?

73 views Asked by At

I found that WMIC doesn't get all installed software because it takes information from some specific/default registry as unique, and that registry alone doesn't contain the full list of software shown on Control Panel.

I found that this Powershell command line DO FIND the software installed listed-and-not-listed by wmic:

Get-ItemProperty HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | select DisplayName, DisplayVersion, InstallDate

BUT, I need to add a FILTER to that line (and I'm sorry I don't know Powershell that deep) to filter for specific name, i.e. 'Teamv', so it shows me ONLY software that start/contain that word, so I can find out if the software is installed or not.

IF (IF) also there exist a way to get from a list of words (let say you want to find out more that one software installed,i.e. Teamviewer, Kaspersky and Logmein) that would be awesome!!

Thanks for any help ! =)

1

There are 1 answers

2
mklement0 On

PowerShell offers the Where-Object cmdlet for filtering a list of objects - wether as a whole or by property values:

Get-ItemProperty `
    HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*,
    HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | 
  Where-Object DisplayName -match 'Teamviewer|Kaspersky|LogMeIn|net' |
  Select-Object DisplayName, DisplayVersion, InstallDate, PSPath

Note:

  • A 64-bit version of Windows is assumed, where you need to check two registry keys: one for 64-bit, and another for 32-bit applications (Wow6432Node).

    • If you want to see which of the two keys the results came from, you can add PSPath to the Select-Object call (the values of that property have a PowerShell-specific provider prefix; to get the registry-native key path, pass these values to Convert-Path).
  • The above, due to involving only a single comparison operation, was able to employ simplified syntax; that is, Where-Object DisplayName -match 'Teamviewer|Kaspersky|LogMeIn' is the simplified form of the following, script block-based form ({ ... }), in which the pipeline input object must be referred to via the automatic $_ variable; you need this form for more complex conditionals:

    Where-Object { $_.DisplayName -match 'Teamviewer|Kaspersky|LogMeIn' }
    
  • That is, the .DisplayName property value of each pipeline input object is compared to a regex (regular expression), 'Teamviewer|Kaspersky|LogMeIn', using the -match operator.

    • The input object at hand is only passed through (output) if the comparison yields $true (possibly by type coercion; here, -match directly returns $true or $false)
    • Notes re -match:
      • It looks for substrings by default, and the alternation construct (|) makes it look for any of the three strings; using additional regex constructs (such as ^ to match only at the start of the input string) would be possible in order to further constrain the matching logic.
      • It is case-insensitive by default, as PowerShell generally is; use the -cmatch variant for case-sensitive matching.