Detect script is running under octopus or not

i have an azure powershell / pester script we’re using to check the deployment, or that the resurces are in the same state they were deployed in. I need to hard code the environment variables at the start if i can’t use variable substitution. I thought i could do something like

if ($octopus) {
  $env = "#{env}"
} else {
  $env = "DR"

but $octopus doesnt work. is there a collection of parameters that i can check if it exists to prove that the script is running under octopus?

Hi Matthew,

Thanks for getting in touch! All of the system variables we create can be found here: and how you can reference them in PowerShell can be found here (not for example that Octopus.Task.Name can be either $OctopusParameters["Octopus.Task.Name"] or $OctopusTaskName.

I’d probably just check for if($OctopusParameters).

Hope that helps!