PowerShell: Check Whether an Application Is Installed Using Known Service Name

# Check whether product is installed
$serviceName='windows_exporter'
function checkUninstall($serviceName){
    $cpuArchitecture32bitPointerSize=4
    $path=if ([IntPtr]::Size -eq $cpuArchitecture32bitPointerSize) {
        'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
    }else{
        @('HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
          'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*')
    }
    Get-ItemProperty $path |.{process{ if ($_.DisplayName -eq $serviceName -and $_.UninstallString) { $_ } }} |
    Select-Object DisplayName, Publisher, InstallDate, DisplayVersion, UninstallString
}
checkUninstall $serviceName

Leave a Reply

Your email address will not be published. Required fields are marked *