Only get project variables in powershell?

Hi,

I see here (http://help.octopusdeploy.com/discussions/questions/3962-looping-through-variables-in-variable-set) that I can loop through all of the available variables in powershell, and am doing that successfully.

Is there a way to only get the variables that are defined in a project’s “Variables” area instead of having all of the system variables included?

I’m trying to avoid including a prefix in the name of each of my variables just to figure out which ones are part of the project.

Thanks!
Stephen

Hi,

Thanks for reaching out. You’ll either need to filter the values from $OctopusParameters as shown on the script below, or include prefixes on your variables (which I agree would be very annoying). I think you can get there with some smart filtering on the where-object side of the pipeline

$variables = $OctopusParameters.getenumerator() | where-object {$_.key -notlike "Octopus.*" -and $_.key -notlike "env:*"}

foreach($variable in $variables)
{
    # Perform the desired action here e.g.
    Write-Output $variable
}

Hope that helps,
Dalmiro