Azure Pipeline – Import WVD Hostpool Token into Azure Secrets

Creating WVD Session Hosts and adding them to the Hostpool requires a token, Once the Hostpool is created through the Azure pipeline, there is a chance that organization norms may not allow Hostpooltoken to be generated and kept open for long time as this may cause problems. So, this article is about how you can dynamically generate a Hostpool token, import it for use and all of it done through an Azure Pipeline!

So just how can one import the Hostpool token into the pipeline to add the session host to the specific Hostpool? Well.. There is not one answer to it.. However i thought i will quickly write something up in PowerShell + Azure pipeline that does the job!

What does this pipeline do?

  • Fetch Hostpool token information from an existing Hostpool.
  • Add the token into Azure Key Vault as a Secret, so it can be fetched and used when deploying the session hosts to the Hostpool
  • All of this done in an Azure pipeline, and can be easily deployed directly in your existing pipeline just before you add the session hosts to the Hostpools.


  • Azure Devops Project setup with Service Connections
  • Azure Github Repository / Azure Devops repository (you may use this code anywhere as per your choice.
  • An existing WVD HostPool
  • An Azure KeyVault
  • An Azure Secret under the Keyvault for the script to write the token to

Variables to update in the pipeline for use:

You May directly use this pipeline into your project, However, be sure to edit the following:

  • $AzureKeyVaultName = <name of your keyvault>
  • $HostpoolTokenSecretName = <name of the keyvault Secret>
  • $HostpoolName =<Name of your HostPool>
  • $ResourceGroup = <Name of the resource group where the Hostpool is deployed>
  • Change the expiration time as per your need (default is set to 6 hours) (Line 24)

Pipeline Link: GitHub-Repo

Other references:
If you are unsure how to build a pipeline? This Link should help
Unsure how to use KeyVault Secrets in Azure pipelines? This Link should help

1 thought on “Azure Pipeline – Import WVD Hostpool Token into Azure Secrets

  1. Pingback: Azure Pipeline – Deploying WVD Session Hosts to Availability Zones vs Availability Sets – V-Desktops

Leave a Reply