Skip to content

Commit

Permalink
Add Include pre-existing session hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
WillyMoselhy committed Aug 15, 2024
1 parent 0d2b71c commit 1173591
Show file tree
Hide file tree
Showing 6 changed files with 819 additions and 801 deletions.
3 changes: 2 additions & 1 deletion FunctionApp/FunctionParameters.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
_Tag_ScalingPlanExclusionTag = @{Required = $false ; Type = 'string' ; Default = 'ScalingPlanExclusion' ; Description = '' }
_TargetVMAgeDays = @{Required = $false ; Type = 'int ' ; Default = 45 ; Description = 'Automatically replaces the session hosts when they are older than X number of days even if there is no new image. The default is 45 days. Setting this value to 0 disables the feature.' }
_DrainGracePeriodHours = @{Required = $false ; Type = 'int ' ; Default = 24 ; Description = '' }
_FixSessionHostTags = @{Required = $false ; Type = 'bool ' ; Default = $true ; Description = '' }
_FixSessionHostTags = @{Required = $false ; Type = 'bool ' ; Default = $true ; Description = 'For Pre-existing Session Hosts, this will add the IncludeInAutomation and DeployTimestamp tags. This is required if IncludePreExistingVMs in enabled.' }
_IncludePreExistingSessionHosts = @{Required = $false ; Type = 'bool ' ; Default = $false ; Description = 'When enabled, the Session Host Replacer will automatically consider pre-existing VMs for replacement if they meet the criteria by setting the IncludeInAutomation tag to True during the first run. When disabled, the session hosts are not counted as part of the target number of VMs. You can manually include a VM after deployment by updating its tag.' }
_SHRDeploymentPrefix = @{Required = $false ; Type = 'string' ; Default = 'AVDSessionHostReplacer' ; Description = '' }
_SessionHostInstanceNumberPadding = @{Required = $false ; Type = 'int ' ; Default = 2 ; Description = '' }
_ReplaceSessionHostOnNewImageVersion = @{Required = $false ; Type = 'bool ' ; Default = $true ; Description = '' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ function Get-SHRSessionHost {
[string] $TagDeployTimestamp = (Get-FunctionConfig _Tag_DeployTimestamp),
[Parameter()]
[string] $TagPendingDrainTimeStamp = (Get-FunctionConfig _Tag_PendingDrainTimestamp),


[Parameter()]
[switch] $FixSessionHostTags
[switch] $FixSessionHostTags,
[Parameter()]
[bool] $IncludePreExistingSessionHosts = (Get-FunctionConfig _IncludePreExistingSessionHosts)

)

Expand Down Expand Up @@ -78,10 +78,10 @@ function Get-SHRSessionHost {
Write-PSFMessage -Level Host -Message 'VM tag {0} with value {1} is not set to True/False' -StringValues $TagIncludeInAutomation, $value
if ($FixSessionHostTags) {
Write-PSFMessage -Level Host -Message 'Setting tag {0} to False' -StringValues $TagIncludeInAutomation
Update-AzTag -ResourceId $item.ResourceId -Tag @{ $TagIncludeInAutomation = 'False' } -Operation Merge
Update-AzTag -ResourceId $item.ResourceId -Tag @{ $TagIncludeInAutomation = "$IncludePreExistingSessionHosts" } -Operation Merge
}

$vmIncludeInAutomation = $false
$vmIncludeInAutomation = $IncludePreExistingSessionHosts
}
#endregion: Tag IncludeInAutomation

Expand Down
7 changes: 7 additions & 0 deletions deploy/bicep/DeployAVDSessionHostReplacer.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ param DrainGracePeriodHours int = 24
@description('Required: 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. | Default: True.')
param FixSessionHostTags bool = true

@description('Required: No | When enabled, the Session Host Replacer will automatically consider pre-existing VMs for replacement if they meet the criteria | Default: False.')
param IncludePreExistingSessionHosts bool = false

@description('Required: No | Prefix used for the deployment name of the session hosts. | Default: AVDSessionHostReplacer')
param SHRDeploymentPrefix string = 'AVDSessionHostReplacer'

Expand Down Expand Up @@ -384,6 +387,10 @@ var varReplacementPlanSettings = [
name: '_FixSessionHostTags'
value: FixSessionHostTags
}
{
name: '_IncludePreExistingSessionHosts'
value: IncludePreExistingSessionHosts
}
{
name: '_SHRDeploymentPrefix'
value: SHRDeploymentPrefix
Expand Down
Loading

0 comments on commit 1173591

Please sign in to comment.