Forum Discussion
mvz12
Feb 14, 2024Copper Contributor
Configure Newly Added to Pool in Drain Mode
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 p...
andrewasdr
Apr 17, 2024Copper Contributor
Hi Mike
Could you please share how to achive this by PowerShell script?
Could you please share how to achive this by PowerShell script?
- MrR0b3rtApr 23, 2024Copper Contributor
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!