This tool automates the deployment and replacement of session hosts in an Azure Virtual Desktop host pool. The best practice for AVD recommends replacing the session hosts instead of maintaining them, the AVD Replacement Plans helps you automate the task of replacing old session hosts with new ones automatically.
You can deploy using Bicep. This will create,
- Function App
- App Service Plan: Consumption tier. Used to host the function.
- Storage Account: Utilized by the function App
- Log Analytics Workspace: Used to store Logs and AppService insights
Deployment Type | Link |
---|---|
PowerShell (Bicep) |
It follows a very simple logic,
- Query the host pool for existing session hosts
- How many session hosts are newer than X number of days?
- Greater than X => Remove the old ones.
- Less than X => Deploy new ones.
The core of an AVD Replacement Plan is an Azure Function App built using PowerShell.
When deploying, the function uses a template and a parameters PowerShell file for the session host. A sample is available here.
When deleting an old session host, the function will check if it has existing sessions and,
- Place the session host drain mode.
- Send a notification to all sessions.
- Add a tag to the session host with a timestamp
- Delete the session host once there are no sessions or the grace period has passed.
Name | required | Description | Type | Default |
---|---|---|---|---|
ADOrganizationalUnitPath | Yes, for Active Directory Domain Services | Distinguished Name of the OU to join session hosts to. | string | |
AppPlanName | No | App Service Plan Name | string | Y1 for consumption based plan |
AppPlanTier | No | App Service Plan Tier | string | Dynamic for consumption based plan |
DrainGracePeriodHours | No | Grace period in hours for session hosts to drain before deletion. | int | 24 hours. |
FixSessionHostTags | No | If true, will apply tags for Include In Auto Replace and Deployment Timestamp to existing session hosts. This will not enable automatic deletion of existing session hosts. | bool | True. |
FunctionAppName | Yes | Name of the Function App. | string | |
FunctionAppZipUrl | No | URL of the FunctionApp.zip file. This is the zip file containing the Function App code. | string | The latest release of the Function App code. |
HostPoolName | Yes | Name of the Azure Virtual Desktop Host Pool. | string | |
HostPoolResourceGroupName | No | Name of the resource group containing the Azure Virtual Desktop Host Pool. | string | The resource group of the Function App. |
Location | No | Region of the Function App. This does not need to be the same as the location of the Azure Virtual Desktop Host Pool. | string | Location of the resource group. |
LogAnalyticsWorkspaceName | Yes | Name of the Log Analytics Workspace used by the Function App Insights. | string | |
MaxSimultaneousDeployments | No | Maximum number of session hosts to deploy at the same time. | int | 20 |
ReplaceSessionHostOnNewImageVersion | No | If true, will replace session hosts when a new image version is detected. | bool | true. |
ReplaceSessionHostOnNewImageVersionDelayDays | No | Delay in days before replacing session hosts when a new image version is detected. | int | 0 (no delay). |
SessionHostInstanceNumberPadding | No | Number of digits to use for the instance number of the session hosts (eg. AVDVM-01). | int | 2. |
SessionHostNamePrefix | Yes | Prefix used for the name of the session hosts. | string | |
SessionHostParameters | Yes | A compressed (one line) json string containing the parameters of the template used to deploy the session hosts. | string | |
SessionHostTemplateUri | Yes | URI of the arm template used to deploy the session hosts. | string | |
SHRDeploymentPrefix | No | Prefix used for the deployment name of the session hosts. | string | AVDSessionHostReplacer |
StorageAccountName | Yes | Name of the storage account used by the Function App. This name must be unique across all existing storage account names in Azure. It must be 3 to 24 characters in length and use numbers and lower-case letters only. | string | |
SubnetId | Yes | Resource ID of the subnet to deploy session hosts to. | string | |
SubscriptionId | No | Subscription ID of the Azure Virtual Desktop Host Pool. | string | The subscription ID of the resource group. |
TagDeployTimestamp | No | Tag name used to indicate the timestamp of the last deployment of a session host. | string | AutoReplaceDeployTimestamp. |
TagIncludeInAutomation | No | Tag name used to indicate that a session host should be included in the automatic replacement process. | string | IncludeInAutoReplace. |
TagPendingDrainTimestamp | No | Tag name used tp indicate drain timestamp of session host pending deletion. | string | AutoReplacePendingDrainTimestamp. |
TagScalingPlanExclusionTag | No | Tag name used to exclude session host from Scaling Plan activities. | string | (None) |
TargetSessionHostCount | Yes | Number of session hosts to maintain in the host pool. | int | |
TargetVMAgeDays | No | Target age of session hosts in days. | int | 45 days |