Skip to content

Instantly share code, notes, and snippets.

@Dalmirog-zz
Created August 25, 2016 19:10
Show Gist options
  • Save Dalmirog-zz/ee1e4a6da28505abc823c06ccc5ec932 to your computer and use it in GitHub Desktop.
Save Dalmirog-zz/ee1e4a6da28505abc823c06ccc5ec932 to your computer and use it in GitHub Desktop.
Get names of machines in role
##CONFIG##
$Role = "" #Role you want to look for
$OctopusAPIkey = "" #API Key for the API calls to get the machine names. Recommended to use a Sensitive Project variable for this.
##PROCESS##
$OctopusURL = $OctopusParameters['Octopus.Web.BaseUrl']
$header = @{ "X-Octopus-ApiKey" = $octopusAPIKey }
$MachineIDs = ($OctopusParameters["Octopus.Environment.MachinesInRole[$Role]"]).Split(',')
$machineNamesArray = @()
foreach ($Id in $MachineIDs){
$MachineNamesArray += ((Invoke-WebRequest $OctopusURL/api/machines/$id -Headers $header -Method Get).content | ConvertFrom-Json | select -ExpandProperty Name)
}
$MachineNamesString = $machineNamesArray -join ","
Set-OctopusVariable -name "MachineNames" -value $MachineNamesString
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment