Get all Target.Machines per Environment per Project


First of all thanks for this great product !

I have been given a task to identify how many machines are used in octopus as Deployment target in respect to all Projects.
Suppose we have 3 Projects : Project-A, Project-B and Project-C
All three projects have 3 environments : Dev, QA, PROD
Each Environment of a project has deployment machines : Server 1, Server 2 and Server 3 (total 9 Machines)

I want to extract this data so that we can identify how many machines are been used in Dev environment under Project A
Currently we have almost 1100 deployment targets and more than 50 environments


Hi Mohammad,

Thanks for getting in touch, and we appreciate the kind words! It’s always great to hear that Octopus has provided value. :slight_smile:

I had a look in our sample script repo and found one that looks to be very close to what you’re after.

I imagine you may want to tweak that to filter machines only in the Dev environment, but I’m curious to hear how close the data returned in that script is to what you need.

Best regards,


Hi Kenny,

Thanks for sharing the feedback on this. I am currently getting a 404 error on Line 60 in this script

Invoke-WebRequest : The remote server returned an error: (404) Not Found.

At line:60 char:36
+ ... tProcess = (Invoke-WebRequest $deploymentProcessUrl -Headers $header) ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Can I test this script on one any test Octopus instances ?

Hi Mohammad,

Thanks for following up! I can’t see the reason why a 404 would be thrown at that point, unfortunately, as it looks to simply be in the foreach loop making a request to the current project. You can test it against the cloud instance using the api key API-GUEST, and that seemed to have run as expected in my identical test. Does that work for you?

Best regards,


This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.