# DQL for gathering all hosts in a specific environment

**URL:** <https://community.dynatrace.com/t/dql-for-gathering-all-hosts-in-a-specific-environment/52035>\
**Category:** DQL\
**Tags:** dql, dynatrace-managed, infrastructure-operations\
**Created:** [June 11, 2025, 1:27pm UTC](https://community.dynatrace.com/t/dql-for-gathering-all-hosts-in-a-specific-environment/52035 "2025-06-11T13:27:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nq44](https://avatars.discourse-cdn.com/v4/letter/n/71e660/32.png) [@nq44](https://community.dynatrace.com/u/nq44)\
**Post date:** [June 11, 2025, 1:27pm UTC](https://community.dynatrace.com/t/dql-for-gathering-all-hosts-in-a-specific-environment/52035/1 "2025-06-11T13:27:51Z")

</div>

I’m trying to gather all the hosts but only this specific environment. What would be a good DQL for that?

---

<div class="post-metadata">

**Author:** ![StrangerThing](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/strangerthing/32/12182_2.png) [@StrangerThing](https://community.dynatrace.com/u/StrangerThing)\
**Post date:** [June 11, 2025, 2:00pm UTC](https://community.dynatrace.com/t/dql-for-gathering-all-hosts-in-a-specific-environment/52035/2 "2025-06-11T14:00:02Z")

</div>

What do you mean by environment? Are you referring to a specific Management Zone or Segment, or something else?

If you just looking to collect all hosts in your entire Dynatrace tenant you can run “fetch dt.entity.host” and it will return all hosts with the default fields of “entity.name” and “id”.

---

<div class="post-metadata">

**Author:** ![TracingMySanity](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@TracingMySanity](https://community.dynatrace.com/u/TracingMySanity)\
**Post date:** [June 11, 2025, 6:10pm UTC](https://community.dynatrace.com/t/dql-for-gathering-all-hosts-in-a-specific-environment/52035/3 "2025-06-11T18:10:29Z")

</div>

I’m not entirely sure of the specific field or attribute you’re looking for when you say “Environment”, but my organization embeds the environment name in the host group name, so you can try to filter on the “hostGroupName” field. You can also try to filter on tags in case the value you’re looking for is included in the tags.

```markup
fetch dt.entity.host
| fieldsAdd hostGroupName, tags
// you can filter for the "environment" like so:
| filter contains(tags, "YOUR_ENV", caseSensitive:false)

```
