Spot computers that doesn't have specific applications installed

As an administrator or Manage Service Provider it is probably your responsibility to setup new computers. You may have a list of applications that as a minium must be installed. Knowing if these applications continues to be available can be tricky once the computer is far away and in the hands of its user.

Here we will show you how a Windows PowerShell script can be used to lookup if required applications are installed. If an application is missing the script will - through the Panorama9 "Custom Issue" feature - report the discrepancy. This will create an issue visible in the Panorama9 Dashboard and send you a notification or create a help desk ticket.  

 

Before you can use the script you must edit it. Change the line:

$apps = @("Skype", "7-Zip %", "VMware %", "Panorama9 %")

The list should be the applications your setup requires. Use % as wildcard.

To see current list of installed applications and get an idea what the script should look for - start a PowerShell prompt and enter:

Get-WmiObject -Class Win32_Product

Once you are satisfied, you can test that the script is able to correctly detect the applications. Just run the script with command-line option "-dry_run". The script will run without creating any Panorama9 issues, but only display what was or was not found.

Last step is to have computers run the script. A way to do this is to configure a logon or logoff script via Group Policy. A simple guide can be found here. Once done your computers will begin to report missing applications.

Copy the PowerShell script below and paste it to a file. It requires that the computer has PowerShell 2.0 or higher installed.

#get command-line arguments
param (
    [switch]$dry_run = $false
)

#list of applications that should be installed (use % as wildcard)
$apps = @("Skype", "7-Zip %", "VMware %", "Panorama9 %")

#path to the P9 custom issue executable
$p9issue = "C:\Program Files\Panorama9\p9-issue.exe"
if (!(Test-Path $p9issue)) {
    $p9issue = "C:\Program Files (x86)\Panorama9\p9-issue.exe"
}

#loop applications list
foreach ($app in $apps) {

    Try {
        #do lookup
        $f = "name like '" + $app + "'"
        $res = Get-WmiObject -Class Win32_Product -filter "$f"

        #was application found?
        if (!$res) {
            "Not installed: $app"
            if(!$dry_run) {
                #p9 custom issue arguments
                $id = $app -replace "[^a-z0-9]"
                $p9issue_id   = '-id="missing' + $id + '"'
                $pretty_app = $app -replace "[ ?%]"
                $p9issue_txt  = '-text="' + $pretty_app + ' not installed"'
                $p9issue_dsc  = '-desc="' + $pretty_app + ' was not found"'
$p9issue_args = '-open', '-type="custom-compliance"', $p9issue_id, $p9issue_txt, $p9issue_dsc, '-ttl="23"' #build p9 custom issue (Start-Process -FilePath $p9issue -ArgumentList $p9issue_args -Wait -Passthru -ErrorAction SilentlyContinue).Exitcode | out-null } } else { "Installed: $app" } } Catch { Write-Warning "error: <$_>" } }

 

 

 

Last updated:

Comments