Created
November 16, 2015 18:42
-
-
Save Dalmirog-zz/6c20de5e49696b446ce6 to your computer and use it in GitHub Desktop.
GetAllMachinesFromDeployment
This file contains hidden or 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
| $APIKey = "" <-#API Key to authenticate to your Octopus server. This is the only parameter you must fill manually. | |
| function GetMachines([string]$APIKey){ | |
| $OctopusURL = $OctopusParameters["Octopus.web.baseurl"] | |
| $IDs = $OctopusParameters["Octopus.Deployment.Machines"] | |
| $MachineIds = $IDS.Split(",") | |
| function Get-FromOctopus([string]$relUrl) { | |
| $uri = "$OctopusUrl$relUrl`?apiKey=$ApiKey" | |
| try { | |
| return Invoke-RestMethod -Uri $uri -Method Get | |
| } | |
| catch { | |
| if ($_.Exception.Response.StatusCode.value__ -eq 404) { | |
| return $null | |
| } else { | |
| throw $_.Exception | |
| } | |
| } | |
| } | |
| foreach($ID in $MachineIds){ | |
| Get-FromOctopus -relUrl "/api/machines/$ID" | |
| } | |
| } | |
| $machines = GetMachines -APIKey $APIKey | |
| ###Your logic goes here | |
| # $Machines will be an array of machine objects. To see all the properties of these objects browse /api/machines/all | |
| #The line below will return the name of the machines in Octopus | |
| $machines.Name | |
| #The line below will return the urls with which the machines were registered in Octopus | |
| #$Machines.uri |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment