powershellfortifyinstalled-applications

Detect if HP Fortify is installed on remote computers


Does anyone have a script to scan a network for a list of hosts to determine if HP Fortify software is installed and provide the version?

I tried using a PowerShell script that scans the add/remove section of the registry but Fortify does not appear there.

Any assistance would be most appreciated!


Solution

  • You have at least 3 ways of accomplishing this.

    1. Using the registry keys HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall and HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninst‌​all (on 64-bit Windows versions) : if the program has been installed with an installer, it should be listed here.

    Here's how you can start:

    $base = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $ComputerName)
    if($key = $base.OpenSubKey("SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall")) {
        foreach($subkey in $key.GetSubKeyNames()) {
            $name = ($key.OpenSubKey($subkey)).GetValue("DisplayName")
            $version = ($key.OpenSubKey($subkey)).GetValue("DisplayVersion")
            if($name) { "$name ($version)" }
        }
    }
    
    1. Using the Win32_Product WMI class (slower, and not all programs appear here):

    Get-WmiObject -ComputerName "127.0.0.1" -Class Win32_Product | Select Name,Version

    1. Using the files for the application themselves, locating the executable that holds the version you need in the C:\Program Files\HP_Fortify directory (or \\$computerName\c$\Program Files\HP_Fortify for a remote computer). You will be able with Get-Item to read the Version property of the desired file.

    With example path C:\Program Files\HP_Fortify\main_service.exe on computer SERVER001:

    $computerName = "SERVER001"
    $exePath = "\\$computerName\c$\Program Files\HP_Fortify\main_service.exe"
    
    if(Test-Path $exePath) {
        (Get-Item $exePath).VersionInfo.ProductVersion
    } else {
        "file not found: $exePath"
    }