Skip to content

Instantly share code, notes, and snippets.

@Dalmirog-zz
Created September 15, 2015 20:36
Show Gist options
  • Select an option

  • Save Dalmirog-zz/a84e98d39ba88431e21f to your computer and use it in GitHub Desktop.

Select an option

Save Dalmirog-zz/a84e98d39ba88431e21f to your computer and use it in GitHub Desktop.
Get all the variables scoped to a specific machine
#This script required the Octoposh module: http://dalmirog.github.io/OctoPosh/
$machine = "" #Name of the machine you want to look variables for.
$MachineID = Get-OctopusMachine -MachineName $machine -ResourceOnly | select -ExpandProperty Id
$variableSets = Get-OctopusVariableSet
$list = @()
foreach ($variableSet in $variableSets){
Foreach ($var in $variableSet.resource.variables){
If($var.scope.Values -ne 0){
[string[]]$scope = $var.Scope.Values
$scope = $scope.split(" ")
If ($Scope -match $MachineID){
$obj = [PSCustomObject]@{
ProjectName = $variableSet.ProjectName
LibrarySetName = $variableSet.LibraryVariableSetName
VariableName = $var.Name
VariableValue = $var.Value
}
$list += $obj
}
}
}
}
$list
@todthomson
Copy link

todthomson commented Jun 28, 2016

Here's a slightly altered version that dumps all variables to a CSV file:

# See: http://help.octopusdeploy.com/discussions/questions/5608-see-all-variables-set-on-a-specific-machine
# A version of: https://gist.github.com/Dalmirog/a84e98d39ba88431e21f
# This script requires the Octoposh module: http://dalmirog.github.io/OctoPosh/

$env:OctopusURL = "http://???"
$env:OctopusAPIKey = "API-???"

Import-Module Octoposh

$variableSets = Get-OctopusVariableSet

$list = @()

foreach ($variableSet in $variableSets)
{
    foreach ($var in $variableSet.resource.variables)
    {
        if ($var.scope.Values -ne 0)
        {
            [string[]]$scope = $var.Scope.Values

            $scope = $scope.split(" ")

            $obj = [PSCustomObject]@{
                ProjectName = $variableSet.ProjectName
                LibrarySetName = $variableSet.LibraryVariableSetName
                VariableName = $var.Name
                VariableValue = $var.Value
            }

            $list += $obj
        }
    } 
}

$list | Export-CSV AllOctopusVars.csv -NoTypeInformation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment