Created
October 20, 2016 01:32
-
-
Save hnrkndrssn/1f78b2eb5cce389766182bdb7ebad616 to your computer and use it in GitHub Desktop.
PowerShell script to register a new SSH target in Octopus using the REST API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$headers = @{"X-Octopus-ApiKey"="API-xxxxxxxxxxxxxxxxxxxxxxxxx"} | |
$environments = Invoke-RestMethod "http://url.to.octopus/api/environments/all" -Headers $headers -Method Get | |
$theEnvironment = $environments | ? { $_.Name -eq "TheEnvironmentName" } | |
$accounts = Invoke-RestMethod "http://url.to.octopus/api/accounts/all" -Headers $headers -Method Get | |
$theAccount = $accounts | ? { $_.Name -eq "TheAccount" } | |
$discovered = Invoke-RestMethod "http://url.to.octopus/api/machines/discover?host=hostnameoripaddress&type=Ssh" -Headers $headers -Method Get | |
#$discovered.Name = "MySshTargetName" # If you wanted to change the name of the deployment target (default is host name) | |
$discovered.Roles += "MyRole" | |
$discovered.EnvironmentIds += $theEnvironment.Id | |
$discovered.Endpoint.AccountId = $theAccount.Id | |
$discovered | ConvertTo-Json -Depth 10 | |
Invoke-RestMethod "http://url.to.octopus/api/machines" -Headers $headers -Method Post -Body ($discovered | ConvertTo-Json -Depth 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment