Forum Discussion

mvz12's avatar
mvz12
Copper Contributor
Feb 14, 2024

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 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. 

  • MrR0b3rt's avatar
    MrR0b3rt
    Copper Contributor
    Unfortunately not, a script is the only solution here. Even discussed this with several Microsoft engineers.

    What I've done in multiple environments is outputting all the host names from the ARM/Bicep deployment and using that output to set all the hosts to drain mode (you might need to do some things with the output parameters to get the correct parameter value, something along the lines of'<host pool name>/<hostname><.ADDomainName (if applicable)>').

    Another plus for using a deployment script is that you can generate a host pool registration key on the fly, so you can automate the deployment even better.
  • andrewasdr's avatar
    andrewasdr
    Copper Contributor
    Hi Mike
    Could you please share how to achive this by PowerShell script?
    • MrR0b3rt's avatar
      MrR0b3rt
      Copper 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!

Resources