Created
August 25, 2016 19:10
-
-
Save Dalmirog-zz/ee1e4a6da28505abc823c06ccc5ec932 to your computer and use it in GitHub Desktop.
Get names of machines in role
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
##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