How to get the Environment ID using Environment name

Hi Team,

We are trying to automate our Octopus CD process, we are creating Environment by providing the name, after creating that new environment I want to get that Environment ID and assign this value to another variable, so that I can use this variable to pass other scripts.
Please provide me some solution to get the Environment ID by using Environment name.


Hi Satish,

Thanks for getting in touch! I believe the best would be to use the API. I have attached a small script which will take the input Environment name and output the Environment ID.

# You can this dll from your Octopus Server/Tentacle installation directory or from

Add-Type -Path 'C:\MyScripts\Octopus.Client\Octopus.Client.dll' 

$apikey = 'API-1234567890abcdefghij' # Get this from your profile
$octopusURI = 'http://OctopusServer/' # Your Octopus Server address
$envName = 'Dev'

$endpoint = New-Object Octopus.Client.OctopusServerEndpoint $octopusURI, $apiKey
$repository = New-Object Octopus.Client.OctopusRepository $endpoint

$envID = $repository.Environments.FindByName($envName).Id


Replace the values for $apikey, $octopusURI, and $envName.

We have some further documentation for our API which may also help in the future.

Let me know if you have any questions here or run into any issues.

Best regards,

Hi Daniel,

Thank you very much for your help, It worked perfectly.


1 Like

Hi Satish,

Thanks for the update! Iā€™m glad this helped.

Please feel free to get in touch at any time. :slight_smile:

Best regards,

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