How to know if a server is attached to a AVD Host Pool

Copper Contributor

Hello everyone! 

I'm wondering if there's a way to search through all the AVD host pools in every subscription to see if that server belongs to a host pool and know the host pool name if exist. 

Is there any way to do that using CLI/Cloud Shell? 
I want to make a script that help us to discover this in a quick way. 

Thanks!

3 Replies
My recommendation would be to use Tags on your host pools or virtual machines. This way you can get all the information filtering on relevant tags. Additionally, if you have a naming standard for session host/host pools you should be able to gather the information from there too.

@nlangoni 

Go into server's Propeties tab and it should show under Host group. 

To determine if a server is attached to an Azure Virtual Desktop (AVD) host pool, you can follow these steps using the Azure CLI or Azure PowerShell:

Retrieve the Object ID of a Host Pool:
Use the following command to get the object ID of a specific host pool:
az desktopvirtualization hostpool show --name <HostPoolName> --resource-group <ResourceGroupName> --query objectId --output tsv

Replace <HostPoolName> and <ResourceGroupName> with the actual names.
Check VMs Associated with the Host Pool:
If you have the object ID from step 1, you can list the VMs associated with that host pool:
az desktopvirtualization sessionhost list --host-pool-name <HostPoolName> --resource-group <ResourceGroupName>

This command will provide information about the session hosts within the specified host pool.
Remember to replace placeholders with actual values. If you encounter any issues or need further assistance, feel free to ask! :smiling_face_with_smiling_eyes: