Feb 14 2024 03:40 PM
Hi,
I need a way to ensure that new hosts being added to a pool are in Drain Mode when they get added. The pool has automatic assignment enabled and we are finding that when new Session Hosts are provisioned users are being assigned before the host gets configuration/apps.
I know how to achieve this using PowerShell but cannot see a way to configure it using ARM template configuration or some configuration on the Host Pool its self.
Is anyone aware of a way to achieve this without scripting? Seems such a basic requirement but no simple way to do it?
Mike.
Feb 19 2024 01:03 AM
Apr 17 2024 05:14 AM
Apr 23 2024 03:57 AM
@andrewasdr Think this might help get you going.
First add the VMs to the output of your deployment template, I use this in my ARM template:
"outputs": {
"virtualMachines": {
"type": "array",
"copy": {
"count": "[variables('virtualMachineInstanceCount')]",
"input": "[reference(resourceId('Microsoft.Compute/virtualMachines', concat(variables('virtualMachineNames')[copyIndex()])), '2020-06-01', 'Full')]"
}
}
}
Using this output, from the New-AzResourceGroupDeployment cmdlet, I populate an array with the VM resources and update the session hosts to not allow new sessions.
$vmResources = @()
foreach( $vm in $deploymentResult.Outputs.virtualMachines.Value ) { $vmResources += ($vm.toString() | ConvertFrom-Json).Properties.osProfile.computerName }
foreach ( $sessionhost in $vmResources ) {
$sessionHostName = "$($sessionhost).domain.local"
Update-AzWvdSessionHost -HostPoolName $hostpoolname -ResourceGroupName $rsgName -Name $sessionHostName -AllowNewSession:$False | Select-Object Name,AllowNewSession
}
The Select part at the end is just to beautify the output, since Update-AzWvdSessionHost returns the updated record and by selecting the Name and AllowNewSessions you get a nice table showing all the session hosts that have been updated.
Hope this helps!