# Retrieve all host group names in the environment via APIs

**URL:** <https://community.dynatrace.com/t/retrieve-all-host-group-names-in-the-environment-via-apis/31755>\
**Category:** Dynatrace API\
**Tags:** dynatrace-api\
**Created:** [June 9, 2021, 6:09pm UTC](https://community.dynatrace.com/t/retrieve-all-host-group-names-in-the-environment-via-apis/31755 "2021-06-09T18:09:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DavidePiras](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/davidepiras/32/29341_2.png) [@DavidePiras](https://community.dynatrace.com/u/DavidePiras)\
**Post date:** [June 9, 2021, 6:09pm UTC](https://community.dynatrace.com/t/retrieve-all-host-group-names-in-the-environment-via-apis/31755/1 "2021-06-09T18:09:52Z")

</div>

I need to use some Dynatrace APIs to retrieve a list of all host groups names configured in our environment,

i do not have host group ids and i do not want to retrieve a single host or host group, simply a full list of ALL&nbsp; distinct host groups names, and their ids in case host groups also have IDs.

what is the easiest set of APIs to use to retrieve this list?

Thanks,

Davide

---

<div class="post-metadata">

**Author:** ![ChadTurner](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/chadturner/32/161_2.png) [@ChadTurner](https://community.dynatrace.com/u/ChadTurner)\
**Post date:** [June 9, 2021, 6:49pm UTC](https://community.dynatrace.com/t/retrieve-all-host-group-names-in-the-environment-via-apis/31755/2 "2021-06-09T18:49:06Z")

</div>

You can do this via the API:

 ![ChadTurner_0-1623264260159.png](https://global.discourse-cdn.com/dynatrace/original/3X/f/d/fdca5544630c19f9f7a02653d4e013e7f810a548.png)

I recommend saving the API Json then importing it to excel where you then can remove unwanted data:

 ![ChadTurner_1-1623264476719.png](https://global.discourse-cdn.com/dynatrace/original/3X/5/9/5940ec91e7d9d3ea0918f9b335c3dce5933bedcb.png)

---

<div class="post-metadata">

**Author:** ![ct\_27](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/ct_27/32/10499_2.png) [@ct\_27](https://community.dynatrace.com/u/ct_27)\
**Post date:** [June 10, 2021, 2:59am UTC](https://community.dynatrace.com/t/retrieve-all-host-group-names-in-the-environment-via-apis/31755/3 "2021-06-10T02:59:35Z")

</div>

I have an equally good solution.&nbsp; &nbsp;Someone had created an amazing set of powershell scripts to also extract administrative type data out of DT.&nbsp; The Git Repo is here:&nbsp;&nbsp;[GitHub - mzball-dt/dynatrace-pwsh: Script utilities for making life easy · GitHub](https://github.com/mzball-dt/dynatrace-pwsh)

Note: Each script has a helpful header that tells you what permissions the token requires, the parameters you can pass in, and some example runs

First create a token with the proper access to run the script. You’ll need it in Step 5

Steps for DT SaaS. If you use Managed then follow the instruction in the Git repo.

1) downloaded and extract the zip

2) Open a powershell prompt (e.g.&nbsp;C:\dynatrace-pwsh-master)

3) navigate to the directory you extracted the code into

4) Enter (replace xxxxx with your SaaS tenant id)

```markup
$env:dtenv='https://xxxxxxxxx.live.dynatrace.com';

```

5) Enter

```markup
$env:dttoken='dt0c01.XXXXXXXXXXX';

```

6) Enter this command and enter ‘Y’. This changes the execution policy so that you can run third-party scripts.

```markup
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass;

```

7) Run any of the scripts you like.

Here are example commands I use frequently to get the data

```markup
C:\dynatrace-pwsh-master\get-tenantHostGroupDetail.ps1 -token dt0c01.xxxxxx -dtenv https://xxxxx.live.dynatrace.com -outfile hostgroup_06092021.csv

C:\dynatrace-pwsh-master\get-tenantHostGroupDetail.ps1 | format-table

C:\dynatrace-pwsh-master\get-tenantHostGroupDetail.ps1 -token dt0c01.xxxxxxxx -dtenv https://xxxxxxx.live.dynatrace.com -summary

```

---

<div class="post-metadata">

**Author:** ![fstekelenburg](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/fstekelenburg/32/22029_2.png) [@fstekelenburg](https://community.dynatrace.com/u/fstekelenburg)\
**Post date:** [February 28, 2023, 10:31am UTC](https://community.dynatrace.com/t/retrieve-all-host-group-names-in-the-environment-via-apis/31755/4 "2023-02-28T10:31:28Z")

</div>

See also Product Idea&nbsp;[Host group visualization in side bar - Dynatrace Community](https://community.dynatrace.com/post/170138)
