Automating tentacle installation and deployment for newly created EC2 instances

We are trying to automate the entire process for spinning up new instances. So far I have machine creation working with Octoposh, and the final command I’m trying to run is octo.exe deploy-release with the following parameters:

$octoExe = “c:\setup\octopus\octo\octo.exe”
$octoArg1 = “deploy-release”
$octoArg2 = “–version=latest”
$octoArg3 = “–deployto”
$octoArg4 = “”
$octoArg5 = “–specificmachines=${TentacleName}”
$octoArg6 = “–server=$OctopusURL”
$octoArg7 = “–apiKey=$OctopusAPIkey”

The problem is that in our first versions, the names were all messed up so it’s pulling crazy versions. Also, pulling “latest” will pull beta / develop builds. I need a way to determine the latest deployment, on production servers.

I was attempting to use octoposh to get this:

Get-OctopusDeployment -project 'MyProject" -Environment “Production”

But it returns failed and successful deployments. I just need the latest, current, working, successful deployment to Production.

I tried passing -State “Success” to Get-OctopusDeployment but that switch is not recognized.

How can I just get the last successful Production version to pass to my octo.exe deploy-release command?