Lee_Dailey

function Get-LD_InstalledSoftware

Sep 21st, 2018
847
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Get-LD_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.         - 2018.09.21.10.04.24
  15.         == changed name to avoid collision with other similar code
  16.     #>
  17.     {
  18.     [CmdletBinding()]
  19.     Param
  20.         (
  21.         # Wildcard characters allowed - and recommended.
  22.         [Parameter()]
  23.         [string]
  24.         $DisplayName = '*',
  25.  
  26.         # Wildcard characters allowed.
  27.         [Parameter()]
  28.         [string]
  29.         $DisplayVersion = '*',
  30.  
  31.         # Use 'yyyyMMdd' format.
  32.         [Parameter()]
  33.         [string]
  34.         $InstallDate = '*',
  35.  
  36.         # Wildcard characters allowed.
  37.         [Parameter()]
  38.         [string]
  39.         $Publisher = '*',
  40.  
  41.         # Wildcard characters allowed, but normally this otta be left to the default.
  42.         [Parameter()]
  43.         [string]
  44.         $UninstallString = '*'
  45.         )
  46.    
  47.     # registry locations for installed software
  48.     $Provider = 'Registry::'
  49.     $All = 'HKEY_LOCAL_MACHINE\SOFTWARE'
  50.     $Current = 'HKEY_CURRENT_USER\SOFTWARE'
  51.     $64_32 = 'Microsoft\Windows\CurrentVersion\Uninstall\*'
  52.     $32_on_64 = 'WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
  53.    
  54.     $RPathAllUser = -join ($Provider, (Join-Path -Path $All -ChildPath $64_32))
  55.     $RPathCurrentUser = -join ($Provider, (Join-Path -Path $Current -ChildPath $64_32))
  56.     $RPathAllUser32 = -join ($Provider, (Join-Path -Path $All -ChildPath $32_on_64))
  57.     $RPathCurrentUser32 = -join ($Provider, (Join-Path -Path $Current -ChildPath $32_on_64))
  58.  
  59.     # get all values from all 4 registry locations
  60.     $Result = Get-ItemProperty -Path $RPathAllUser, $RPathCurrentUser, $RPathAllUser32, $RPathCurrentUser32 |
  61.         # skip items without a DisplayName
  62.         Where-Object DisplayName -ne $null |
  63.         Where-Object {
  64.             $_.DisplayName -like $DisplayName -and
  65.             $_.DisplayVersion -like $DisplayVersion -and
  66.             $_.InstallDate -like $InstallDate -and
  67.             $_.Publisher -like $Publisher -and
  68.             $_.UninstallString -like $UninstallString
  69.             } |
  70.         Sort-Object -Property DisplayName
  71.  
  72.     $Result
  73.     }
Advertisement
Add Comment
Please, Sign In to add comment