How can I find tentacles that have an upgrade available?

This script will print the tentacle version and status for each tentacle target. It can be customized to only display targets that have updates available. You can find this script in other languages here.

Note: Please modify and test the script provided before relying on it for production purposes.

# Define working variables
$octopusURL = "https://your.octopus.app/api"
$octopusAPIKey = "API-YOURAPIKEY"
$header = @{ "X-Octopus-ApiKey" = $octopusAPIKey }
$spaceName = "Default"

try {
    # Get space id
    $spaces = Invoke-RestMethod -Method Get -Uri "$octopusURL/spaces/all" -Headers $header -ErrorVariable octoError
    $space = $spaces | Where-Object { $_.Name -eq $spaceName }
    Write-Host "Using Space named $($space.Name) with id $($space.Id)"

    # Create space specific url
    $octopusSpaceUrl = "$octopusURL/$($space.Id)"

    # Get tentacles
    $targets = Invoke-RestMethod -Method Get -Uri "$octopusSpaceUrl/machines/all" -Headers $header -ErrorVariable octoError
    $workers = Invoke-RestMethod -Method Get -Uri "$octopusSpaceUrl/workers/all" -Headers $header -ErrorVariable octoError

    ($targets + $workers)
    | Where-Object { $_.Endpoint -and $_.Endpoint.TentacleVersionDetails }
    | ForEach-Object {
        Write-Host "Checking Tentacle version for $($_.Name)"
        $details = $_.Endpoint.TentacleVersionDetails

        Write-Host "`tTentacle status: $($_.HealthStatus)"
        Write-Host "`tCurrent version: $($details.Version)"
        Write-Host "`tUpgrade suggested: $($details.UpgradeSuggested)"
        Write-Host "`tUpgrade required: $($details.UpgradeRequired)"
    }
}
catch {
    Write-Host "There was an error during the request: $($octoError.Message)"
    exit
}

Example output:

Using Space named Default with id Spaces-1
Checking tentacle version for doctofxvm
        Target status: Healthy
        Current version: 5.0.12
        Upgrade suggested: False
        Upgrade required: False
Checking tentacle version for drandomquotesvm
        Target status: Healthy
        Current version: 5.0.12
        Upgrade suggested: False
        Upgrade required: False
Checking tentacle version for poctofxvm
        Target status: Healthy
        Current version: 5.0.12
        Upgrade suggested: False
        Upgrade required: False
Checking tentacle version for prandomquotesvm
        Target status: Healthy
        Current version: 5.0.12
        Upgrade suggested: False
        Upgrade required: False
Checking tentacle version for preoctofxvm
        Target status: Healthy
        Current version: 5.0.12
        Upgrade suggested: False
        Upgrade required: False
Checking tentacle version for prerandomquotesvm
        Target status: Healthy
        Current version: 5.0.12
        Upgrade suggested: False
        Upgrade required: False
Checking tentacle version for spinoctofxvm
        Target status: Healthy
        Current version: 5.0.12
        Upgrade suggested: False
        Upgrade required: False
Checking tentacle version for spinrandomquotesvm
        Target status: Healthy
        Current version: 5.0.12
        Upgrade suggested: False
        Upgrade required: False
Checking tentacle version for toctofxvm
        Target status: Healthy
        Current version: 5.0.12
        Upgrade suggested: False
        Upgrade required: False
Checking tentacle version for trandomquotesvm
        Target status: Healthy
        Current version: 5.0.12
        Upgrade suggested: False
        Upgrade required: False