Can I get help with a script to take an action based on the version of an installed application?

I need to deploy software update to all company machines but don't want to run it if the version of the app is the same as the update. So far I have the script below. It works fine for displaying the application info, but I just need it to look at the version of the app and take an action. It'd be nice if i could use the same script for other applications too.

EDIT: And I do not want to use WMI. You'll see in the script that I'm scraping the application info from the registry. I prefer this method.

Function Get-InstalledPrograms{
Param($computername,$filter = "*")
$UninstallKey="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall" 
$reg = [microsoft.win32.registrykey]::openremotebasekey('LocalMachine',$computername)
$regkey = $reg.OpenSubKey($UninstallKey)
$subkeys=$regkey.GetSubKeyNames() 


$return = foreach($key in $subkeys){

    $thisKey=$UninstallKey+"\\"+$key 

    $thisSubKey=$reg.OpenSubKey($thisKey) 

    $obj = New-Object PSObject

    $obj | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $computername

    $obj | Add-Member -MemberType NoteProperty -Name "DisplayName" -Value $($thisSubKey.GetValue("DisplayName"))

    $obj | Add-Member -MemberType NoteProperty -Name "DisplayVersion" -Value $($thisSubKey.GetValue("DisplayVersion"))

    $obj | Add-Member -MemberType NoteProperty -Name "InstallLocation" -Value $($thisSubKey.GetValue("InstallLocation"))

    $obj | Add-Member -MemberType NoteProperty -Name "Publisher" -Value $($thisSubKey.GetValue("Publisher"))

    $obj


} 
#checks to see if system is using 64bit windows
if (test-path (join-path $env:windir "Syswow64")){
$UninstallKey="SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\Currentversion\\Uninstall" 
$reg = [microsoft.win32.registrykey]::openremotebasekey('LocalMachine',$computername)
$regkey = $reg.OpenSubKey($UninstallKey)
$subkeys=$regkey.GetSubKeyNames() 

$return = foreach($key in $subkeys){

    $thisKey=$UninstallKey+"\\"+$key 

    $thisSubKey=$reg.OpenSubKey($thisKey) 

    $obj = New-Object PSObject

    $obj | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $computername

    $obj | Add-Member -MemberType NoteProperty -Name "DisplayName" -Value $($thisSubKey.GetValue("DisplayName"))

    $obj | Add-Member -MemberType NoteProperty -Name "DisplayVersion" -Value $($thisSubKey.GetValue("DisplayVersion"))

    $obj | Add-Member -MemberType NoteProperty -Name "InstallLocation" -Value $($thisSubKey.GetValue("InstallLocation"))

    $obj | Add-Member -MemberType NoteProperty -Name "Publisher" -Value $($thisSubKey.GetValue("Publisher"))

    $obj


} 


}

if( $return -ne $null ){
return $return | Where {$_.DisplayName -like ("*"+$filter+"*")}}

}


July 24th, 2015 11:59am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics