Get all servers with a role

Is there any way to get a list of servers that belong to a particular role? Occasionally, I get questions about what servers are hosting a certain service and I need to get this list. I can’t really see an easy way to get the servers in a role.

Hi Casey,

Thanks for reaching out!

The best way to do this would be using our API. There’s a Powershell module called Octoposh thats written on top of our API that hast a cmdlet called Get-OctopusMachine which could be really helpful in this case.

For example If you want to get all the machines with the role “WebServer” inside of the “Production” environment, you could run

$Environment = "Production"
$Role = "WebServer"

$MachinesInEnv = Get-OctopusMachine -EnvironmentName $Environment
$MachinesWithRole = $MachinesInEnv | ?{$role -in $_.Roles}


Octoposh site:
Cmdlet help:

Let me know if that helps,