Jun 09, 2023 Azure

Automating AVD Deployment

Hello all! It’s been a long time!

Today’s post is a bit different, I want to share one pipeline task that can help you to automate the deployment of AVD session hosts.

This automation contains some powershell scripts that help you to:

  • Send notifications to Active Users.
  • Delete AVD Session Hosts.
  • Create Session Hosts.
  • Delete ADDS computer accounts.
  • Add VMs to a specific Log Analytics workspace.

Send-UserNotification.ps1

The user notification.ps1 is responsible for checking if the available session hosts contain any active session and, if the session state is equal to “Active”, the script sends a notification to the user desktop warning them that the environment will become unavailable for a couple of minutes. It also allows the user to end their pending tasks (by default, the script waits 5 minutes)

Execution example

#Execution example

./avdUserNotification.ps1   -avdHostPoolName <hostPoolName> `
                            -avdResourceGroupName <avdResourceGroupName> `
                            -avdSubscriptionName <avdSubscriptionName or SubscriptionId>

Delete-SessionHost.ps1

The deleteSessionHost.ps1 is responsible to delete the VMs and dependencies (Disk and Network Adapter).

#Execution example

./deleteSessionHost.ps1 -avdHostPoolName <hostPoolName> `
                        -avdResourceGroupName <avdResourceGroupName> `
                        -avdSubscriptionName <Subscription name or SubscriptionId>

Delete-ADDSComputerAccount.ps1

The deleteAdComputerAccount.ps1 is responsible to delete the computer accounts in a specified organizational unity and, to this we used the parameter called credential to specify a user that has the privilege to manage the OU.

To grant access to a specific OU, you can use the delegation control.

#Execution Example
./deleteAdComputerAccount   `
                            -ouPath <OU=FSLOGIX,OU=AZURE-VIRTUAL-DESKTOP,OU=COMPUTERS,OU=ORGANIZATION,DC=myDomain,DC=com> `
                            -userName <DOMAINNAME\USER> `
                            -kvName <myKeyVault> `
                            -secretName <mySecretName> `
                            -subscriptionKeyVault <subscriptionKeyVault> `
                            -domainControllerName <domainControllerName> 

Add-SessionHostToLaws.ps1

The addVmToLawsWorkspace.ps1 is used to configure the VMs in a specific logAnalitcs workspace in case your team uses the AVD Insights Preview.

#Execution Example
./deleteAdComputerAccount   `
                            -subscription <"subscription where the vm's  where deployed">  `
                            -workspaceId <Id of the workspace used for AVD/VM Insights> `
                            -workspaceKey <Secret key of the Workspace> `
                            -avdVmsResourceGroup "Resource group used to store the AVD VMs"

New-AzDeployment.ps1

The newAzSessionHostDeployment.ps1 is responsible to trigger the deployment of the session hosts.

The base templates are available in this repository but, you can use your own. Microsoft also has documentation for AVD and automation that you can take a look to improve your environment.

#Execution Example
./newAzSessionHostDeployment    `
                                -templateFile <sessionHostTemplate/template.json> `
                                  -templateParametersFile <sessionHostTemplate/parameters.json> `
                                  -avdResourceGroupName <avdResourceGroupName> `
                                  -subscription <yourSubscriptionid> 

For more details about this automation, please check my public repo.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.