I am new on Octopus Deploy. According to me, it’s very interessting.
Now, I am looking for for a PowerShell request to list machines of an environment. I’ve tried this:
$repository.Environments.FindByName(‘MyEnv’) |gm but I don’t find any related property nor Method.
To get all the machines in a given environment, you can do something like this:
Add-Type -Path 'Octopus.Client.dll'
$apikey = 'API-1234' # Get this from your profile
$octopusURI = 'https://youroctopus.com' # Your server address
$endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI,$apikey
$repository = New-Object Octopus.Client.OctopusRepository $endpoint
$env = $repository.Environments.FindByName("MyEnv")
$machinesInEnvironment = ($repository.Machines.FindMany({ param($m) $m.EnvironmentIds -contains $env.Id }))
That will return a list of all the machines that are in that environment.
From a more general point of view, you can learn a lot from our samples repository - there’s often a script in there that is very similar to what you’re trying to do.
Another useful reference is the source code for OctopusClients, which can help you figure out what methods you can call.