Advertisement
Lee_Dailey

function Get-InstalledSoftware

Nov 10th, 2017
817
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Get-InstalledSoftware
  2.     <#
  3.     .SYNOPSIS
  4.         Get Installed software via the registry.
  5.  
  6.     .NOTES
  7.         Original source ...
  8.         Find Installed Software - Power Tips - PowerTips - IDERA Community
  9.         - http://community.idera.com/powershell/powertips/b/tips/posts/find-installed-software
  10.  
  11.         Version
  12.         - 2017.09.22.23.35.49
  13.         == added Publisher search item
  14.     #>
  15.     {
  16.     [CmdletBinding()]
  17.     Param
  18.         (
  19.         # Wildcard characters allowed - and recommended.
  20.         [Parameter()]
  21.         [string]
  22.         $DisplayName = '*',
  23.  
  24.         # Wildcard characters allowed.
  25.         [Parameter()]
  26.         [string]
  27.         $DisplayVersion = '*',
  28.  
  29.         # Use 'yyyyMMdd' format.
  30.         [Parameter()]
  31.         [string]
  32.         $InstallDate = '*',
  33.  
  34.         # Wildcard characters allowed.
  35.         [Parameter()]
  36.         [string]
  37.         $Publisher = '*',
  38.  
  39.         # Wildcard characters allowed, but normally this otta be left to the default.
  40.         [Parameter()]
  41.         [string]
  42.         $UninstallString = '*'
  43.         )
  44.    
  45.     # registry locations for installed software
  46.     $Provider = 'Registry::'
  47.     $All = 'HKEY_LOCAL_MACHINE\SOFTWARE'
  48.     $Current = 'HKEY_CURRENT_USER\SOFTWARE'
  49.     $64_32 = 'Microsoft\Windows\CurrentVersion\Uninstall\*'
  50.     $32_on_64 = 'WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
  51.    
  52.     $RPathAllUser = -join ($Provider, (Join-Path -Path $All -ChildPath $64_32))
  53.     $RPathCurrentUser = -join ($Provider, (Join-Path -Path $Current -ChildPath $64_32))
  54.     $RPathAllUser32 = -join ($Provider, (Join-Path -Path $All -ChildPath $32_on_64))
  55.     $RPathCurrentUser32 = -join ($Provider, (Join-Path -Path $Current -ChildPath $32_on_64))
  56.  
  57.     # get all values from all 4 registry locations
  58.     $Result = Get-ItemProperty -Path $RPathAllUser, $RPathCurrentUser, $RPathAllUser32, $RPathCurrentUser32 |
  59.         # skip items without a DisplayName
  60.         Where-Object DisplayName -ne $null |
  61.         Where-Object {
  62.             $_.DisplayName -like $DisplayName -and
  63.             $_.DisplayVersion -like $DisplayVersion -and
  64.             $_.InstallDate -like $InstallDate -and
  65.             $_.Publisher -like $Publisher -and
  66.             $_.UninstallString -like $UninstallString
  67.             } |
  68.         Sort-Object -Property DisplayName
  69.  
  70.     $Result
  71.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement