LogicalDesk
LogicalDesk

Reputation: 1297

Find out the current version and update of an installed application

I have some requirement where I have to find out the current version and update details of an installed application (highlighted):

enter image description here

And I have this PowerShell snippet for modification:

$server="XXXXXXXXXX"

$ServiceInfo = Get-WmiObject win32_service -ComputerName $server -ExpandProperty Version | Where-Object {$_.Name -eq "VSTTAgent"} 
if($ServiceInfo.State -eq "Running")
{
    $userAccount = $ServiceInfo.DisplayName.ToString()
    Write-Host ("VSTTAgent service is Running on $server and  $userAccount  ")                  
}

Upvotes: 1

Views: 1254

Answers (2)

Chris Dent
Chris Dent

Reputation: 4240

Essentially the same as @MartinBrandl, but the WMI-only version.

Get-WmiObject win32_service -Filter 'Name="VSTTAgent"' -ComputerName $server | ForEach-Object {
    $filter = 'Name="{0}"' -f $_.PathName -replace '\\', '\\'
    $version = (Get-WmiObject CIM_DataFile -Filter $filter -ComputerName $server).Version

    if ($_.State -eq 'Running') {
        $userAccount = $ServiceInfo.DisplayName.ToString()
        Write-Host ("VSTTAgent ($version) service is Running on $server and  $userAccount")
    }
}

Upvotes: 1

Martin Brandl
Martin Brandl

Reputation: 58931

To get the product version, you can use the Get-Item cmdlet using the PathName property of your $ServiceInfo object:

$ServiceInfo.PathName.Trim('"') | Get-Item | select -expand VersionInfo | select ProductVersion

Upvotes: 1

Related Questions