Get list of machines in a named role Octopus Deploy 2.4.7.85

I’m using Octopus Deploy 2.4.7.85 and want to run a powershell script on machine a that calls an API with the names of the machines in a particular role.

Is it possible in a powershell step on machine with role-a to get a list of the names of the machines in role-b?

I’ve found Octopus.Environment.MachinesInRole[_role_] in the current docs but that appears to be an empty string

Hi,

Thanks for reaching out!

That version of Octopus is really old by now (I didn’t even get to use it myself!), so I can’t guarantee the below snippet will work. But hopefully that part of the API hasn’t changed since then.

###Config###

$OctopusAPIKey = "" #API key to authenticate with the Octopus API
$RoleFilter = "" #Role you want to filter for.

###Process###

$OctopusBaseURL = $OctopusParameters['Octopus.Web.BaseUrl']

$EnvironmentID = $OctopusParameters['Octopus.Environment.Id']

$header = @{ "X-Octopus-ApiKey" = $OctopusAPIKey }

$AllMachines = (Invoke-WebRequest $OctopusBaseURL/api/environments/$EnvironmentID/machines -Headers $header | ConvertFrom-Json).items

$Machines = $AllMachines |?{$_.roles -icontains $RoleFilter}

$Machines.Name

Regards,
Dalmiro

I forgot to mention that the empty Octopus.Environment.MachinesInRole[\_role\_] is a bug we fixed a long time ago.

Do you have any plans on upgrading from that 2.4 instance?

I’d love to be able to upgrade from that instance :slight_smile:

I’ll try the script you provided and see what I find. Thanks

We have a guide to upgrade from 2.6 to the latest: https://octopus.com/docs/administration/upgrading/upgrading-from-octopus-2.6

You’ll need to manually upgrade from 2.4 to 2.6 first.

Definitely something you want to take some time to plan though :slight_smile: