# How to define tags based on environment variables for clusters?

**URL:** <https://community.dynatrace.com/t/how-to-define-tags-based-on-environment-variables-for-clusters/41569>\
**Category:** Open Q&A\
**Tags:** windows, databases, mssql, tagging\
**Created:** [September 8, 2023, 8:19am UTC](https://community.dynatrace.com/t/how-to-define-tags-based-on-environment-variables-for-clusters/41569 "2023-09-08T08:19:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![renatarc](https://avatars.discourse-cdn.com/v4/letter/r/3be4f8/32.png) [@renatarc](https://community.dynatrace.com/u/renatarc)\
**Post date:** [September 8, 2023, 8:19am UTC](https://community.dynatrace.com/t/how-to-define-tags-based-on-environment-variables-for-clusters/41569/1 "2023-09-08T08:19:08Z")

</div>

Hello

We’ve defined&nbsp;tags based on environment variables for the MS SQL Server instances.

It works fine on standalone instances, but it doesn’t work for instances on cluster.

The “Environment” variable is already used by the cluster configuration.&nbsp;The manual setup done for the Dynatrace’s tag ( **DT\_CUSTOM\_PROP= and** &nbsp; **DT\_TAGS=** ) disapears after the restart of MSSQL service.

I followed the instructions on the page :&nbsp;[Define tags based on environment variables — Dynatrace Docs](https://www.dynatrace.com/support/help/manage/tags-and-metadata/setup/define-tags-based-on-environment-variables#expand--how-to-define-an-environment-variable-for-windows--2)

Do you know how to setup the variables for SQL server&nbsp;clusters ?

Thanks,

Renata

---

<div class="post-metadata">

**Author:** ![radek\_jasinski](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/radek_jasinski/32/10432_2.png) [@radek\_jasinski](https://community.dynatrace.com/u/radek_jasinski)\
**Post date:** [September 8, 2023, 10:07am UTC](https://community.dynatrace.com/t/how-to-define-tags-based-on-environment-variables-for-clusters/41569/2 "2023-09-08T10:07:45Z")

</div>

Hi Renata,

I understand that you have correctly added variables to the registry on all servers in the cluster where you have MS SQL?

> **[Define your own process group metadata](https://docs.dynatrace.com/docs/observe/infrastructure-observability/process-groups/configuration/define-your-own-process-group-metadata)**
>
> Configure your own process-related metadata based on the unique needs of your organization or environment.

Don’t you sometimes have a mechanism in the organization that verifies the configuration of servers and, if changes are detected, restores the original one.

Radek

---

<div class="post-metadata">

**Author:** ![renatarc](https://avatars.discourse-cdn.com/v4/letter/r/3be4f8/32.png) [@renatarc](https://community.dynatrace.com/u/renatarc)\
**Post date:** [September 8, 2023, 12:25pm UTC](https://community.dynatrace.com/t/how-to-define-tags-based-on-environment-variables-for-clusters/41569/3 "2023-09-08T12:25:08Z")

</div>

Hi Radek

There is any in-house script to restore the original values of the variables.

This configuration of the variables might be at the Cluster Manager level (quorum), but I don’t know where/how to setup them.

Regards,

Renata

---

<div class="post-metadata">

**Author:** ![radek\_jasinski](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/radek_jasinski/32/10432_2.png) [@radek\_jasinski](https://community.dynatrace.com/u/radek_jasinski)\
**Post date:** [September 8, 2023, 12:36pm UTC](https://community.dynatrace.com/t/how-to-define-tags-based-on-environment-variables-for-clusters/41569/4 "2023-09-08T12:36:57Z")

</div>

To set an environment variable using PowerShell and make it persistent (available even after a system reboot), you can use the following command:

**[Environment]::SetEnvironmentVariable(“VARIABLE\_NAME”, “VARIABLE\_VALUE”,[System.EnvironmentVariableTarget]::Machine)**

Where:

- VARIABLE\_NAME is the name of the environment variable you want to set.
- VARIABLE\_VALUE is the value you want to assign to this variable.
- [System.EnvironmentVariableTarget]::Machine means that the variable will be set as a machine variable, which means it will be available to all users on that computer and will be persistent.

> **[Set Environment Variable using PowerShell - ShellGeek](https://shellgeek.com/set-environment-variable-using-powershell/)**
>
> $env:Path in PowerShell to set environment variable for the session or temporary.\[System. Environment\] set environment variable permanently.

See if this works:)

Radek

---

<div class="post-metadata">

**Author:** ![renatarc](https://avatars.discourse-cdn.com/v4/letter/r/3be4f8/32.png) [@renatarc](https://community.dynatrace.com/u/renatarc)\
**Post date:** [September 8, 2023, 12:52pm UTC](https://community.dynatrace.com/t/how-to-define-tags-based-on-environment-variables-for-clusters/41569/5 "2023-09-08T12:52:05Z")

</div>

Thanks for your inputs.

I need to have the “tag” on Dynatrace only in the processes and Process Groups related to the MS SQL Server Service.&nbsp;That’s why on Windows, it has to be set in the registry of Service and not as a System Variable.

If I set the variable in the system, the server and all the processes will be tagged in Dynatrace with this variable - this is not the goal.

The documentation Dynatrace ([Define tags based on environment variables](https://www.dynatrace.com/support/help/manage/tags-and-metadata/setup/define-tags-based-on-environment-variables?_ga=2.93742751.304844845.1694159519-927780096.1691067861&_gl=1*wowg3i*_ga*OTI3NzgwMDk2LjE2OTEwNjc4NjE.*_ga_1MEMV02JXV*MTY5NDE3MTYwMy4yMS4xLjE2OTQxNzcwMDEuMC4wLjA.#expand--how-to-define-an-environment-variable-for-windows--2)&nbsp;) says :

| Applying&nbsp;[tags](https://www.dynatrace.com/support/help/manage/tags-and-metadata/setup/how-to-define-tags)&nbsp;to hosts (instead of thoughtfully setting up environment variables as explained here) isn’t recommended. The same applies to applications and processes. For details on setting up the&nbsp;DT\_CUSTOM\_PROP&nbsp;environment variable for Tomcat or WebSphere application metadata, Kubernetes annotations for Kubernetes-based deployments, or AWS tagging, see&nbsp;[Application metadata & tagging](https://www.dynatrace.com/support/help/manage/tags-and-metadata/basic-concepts/best-practices-and-recommendations-for-tagging#application-metadata-and-tagging). |
| --- |

---

<div class="post-metadata">

**Author:** ![radek\_jasinski](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/radek_jasinski/32/10432_2.png) [@radek\_jasinski](https://community.dynatrace.com/u/radek_jasinski)\
**Post date:** [September 11, 2023, 7:31am UTC](https://community.dynatrace.com/t/how-to-define-tags-based-on-environment-variables-for-clusters/41569/6 "2023-09-11T07:31:52Z")

</div>

If you want to set a permanent variable for a specific process or group of processes in windows then you can do it this way:

You can use PowerShell to create or modify environment variables in the Windows Registry.

_# Define permanent environment variables for different process groups_  
_$RegistryPath = “HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment”_

_# Group A Variables_  
_$GroupA\_Variable1 = “ValueA1”_  
_$GroupA\_Variable2 = “ValueA2”_

_# Group B Variables_  
_$GroupB\_Variable1 = “ValueB1”_  
_$GroupB\_Variable2 = “ValueB2”_

_# Set Group A Variables_  
_Set-ItemProperty -Path $RegistryPath -Name “GroupA\_Variable1” -Value $GroupA\_Variable1_  
_Set-ItemProperty -Path $RegistryPath -Name “GroupA\_Variable2” -Value $GroupA\_Variable2_

_# Set Group B Variables_  
_Set-ItemProperty -Path $RegistryPath -Name “GroupB\_Variable1” -Value $GroupB\_Variable1_  
_Set-ItemProperty -Path $RegistryPath -Name “GroupB\_Variable2” -Value $GroupB\_Variable2_

In the above example, you set permanent environment variables for different process groups (GroupA\_Variable1, GroupA\_Variable2, GroupB\_Variable1, and GroupB\_Variable2) in the Windows Registry under HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment. These variables will persist and be available to all processes system-wide.

After setting permanent environment variables, you may need to restart or refresh processes (such as Explorer or PowerShell sessions) for them to recognize the new variables.

Radek
