Streamline repeating sections
I was wondering how would I streamline this further?
With a 64-bit OS I have to look in the Wow6432node section of the registry as well but there's a fair amount of repeating code.
$SOFTWARE = 'hp'
$OSbit = Get-WmiObject win32_operatingsystem | Select-Object -ExpandProperty osarchitecture
if ($OSbit -eq '64-bit') {
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*, HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |
Select-Object DisplayName, DisplayVersion, uninstallstring |
Where-Object {$_.DisplayName -like "*$software*"}
} else {
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |
Select-Object DisplayName, DisplayVersion, uninstallstring |
Where-Object {$_.DisplayName -like "*$software*"}
}
Posted Nov 30, 2017, 11:42 AM UTC · edited
Perhaps something like
Oh I like it - thanks very much!