Environment Name Variable in Powershell Step

I am using a PowerShell step after my application is deployed as a package. Can you reference the Octopus environment name in the PowerShell step?
I tried a project variable with then name “ENV” and a value of #{Octopus.Environment.Name} but this didnt work.
We are running version 3.5.1.
The reason i ask is i read somewhere you cannt use these variables in a powershell step.

Hi Shane,

Thanks for getting in touch! Substituting in #{Octopus.Environment.Name} into a project variable is supported, so I’m not sure why it’s not working as expected for you. Can you send a screenshot showing this variable in the web portal, and also the PowerShell script you’re using it in? I’ll be happy to give it a test and see if we can spot what’s causing this behavior.

If any of this is sensitive, feel free to mark this thread as private, or email the info to us at support at octopus dot com and I can retrieve it there. :slight_smile:

Best regards,


Hi Kenny

Thanks for the quick response.

A screenshot below showing the project variable, and then we reference the $ENV in the PowerShell step. Should this work? I can send the PowerShell just need to take some stuff out.


Hi Shane,

Thanks for following up. That looks like it should work as you have it. Are you able to instead get the ENV variable value by calling it with the syntax $OctopusParameters["ENV"] by chance?

To continue troubleshooting this issue, we have a doc page on debugging problems with variables that outlines two debugging variables you can add to your project (OctopusPrintVariables and OctopusPrintEvaluatedVariables) which will write to your task log every variable at the beginning of each step and what they evaluate into.

That should help shed more light on what’s causing this. If you’d like to send it over to us, feel free to mark this thread as private, or email it to support at octopus dot com and I can get it there. :slight_smile:

I hope this helps!

Best regards,


This might just an unfortunate choice of variable name - don’t forget that “$env” is a default PSDrive in a Windows PowerShell command prompt which refers to the process’s environment variables:

PS C:\Users\Mike> Get-PSDrive env

Name           Used (GB)     Free (GB) Provider      Root                                               CurrentLocation
----           ---------     --------- --------      ----                                               ---------------
Env                                    Environment

PS C:\Users\Mike> $env:COMPUTERNAME

If it is that, using $OctopusParameters[“ENV”] instead might help with accessing the value defined by Octopus rather than the PSDrive.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.