Skip to content

Commit 74793d3

Browse files
authored
Merge pull request #264134 from sipastak/autoscale-powershell
AVD Autoscale powershell
2 parents 33a4507 + fa5d6f7 commit 74793d3

File tree

1 file changed

+212
-17
lines changed

1 file changed

+212
-17
lines changed

articles/virtual-desktop/autoscale-scaling-plan.md

Lines changed: 212 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ title: Create and assign an autoscale scaling plan for Azure Virtual Desktop
33
description: How to create and assign an autoscale scaling plan to optimize deployment costs.
44
author: Heidilohr
55
ms.topic: how-to
6-
ms.date: 01/16/2024
6+
ms.date: 01/10/2024
77
ms.author: helohr
8+
manager: femila
89
ms.custom: references_regions
910
---
1011
# Create and assign an autoscale scaling plan for Azure Virtual Desktop
@@ -33,6 +34,7 @@ To use scaling plans, make sure you follow these guidelines:
3334
> [!IMPORTANT]
3435
> Hibernation is currently in PREVIEW.
3536
> See the [Supplemental Terms of Use for Microsoft Azure Previews](https://azure.microsoft.com/support/legal/preview-supplemental-terms/) for legal terms that apply to Azure features that are in beta, preview, or otherwise not yet released into general availability.
37+
- If you are using PowerShell to create and assign your scaling plan, you will need module [Az.DesktopVirtualization](https://www.powershellgallery.com/packages/Az.DesktopVirtualization/) version 4.2.0 or later.
3638

3739
## Assign the Desktop Virtualization Power On Off Contributor role with the Azure portal
3840

@@ -42,7 +44,9 @@ To learn how to assign the *Desktop Virtualization Power On Off Contributor* rol
4244

4345
## Create a scaling plan
4446

45-
Now that you've assigned the *Desktop Virtualization Power On Off Contributor* role to the service principal on your subscriptions, you can create a scaling plan. To create a scaling plan:
47+
### [Portal](#tab/portal)
48+
49+
Now that you've assigned the *Desktop Virtualization Power On Off Contributor* role to the service principal on your subscriptions, you can create a scaling plan. To create a scaling plan using the portal:
4650

4751
1. Sign in to the [Azure portal](https://portal.azure.com).
4852

@@ -72,7 +76,7 @@ Now that you've assigned the *Desktop Virtualization Power On Off Contributor* r
7276
7377
1. Select **Next**, which should take you to the **Schedules** tab. Schedules let you define when autoscale turns VMs on and off throughout the day. The schedule parameters are different based on the **Host pool type** you chose for the scaling plan.
7478

75-
#### [Pooled host pools](#tab/pooled-autoscale)
79+
#### Pooled host pools
7680

7781
In each phase of the schedule, autoscale only turns off VMs when in doing so the used host pool capacity won't exceed the capacity threshold. The default values you'll see when you try to create a schedule are the suggested values for weekdays, but you can change them as needed.
7882

@@ -124,7 +128,7 @@ Now that you've assigned the *Desktop Virtualization Power On Off Contributor* r
124128
- Load-balancing algorithm. We recommend choosing **depth-first** to gradually reduce the number of session hosts based on sessions on each VM.
125129
- Just like peak hours, you can't configure the capacity threshold here. Instead, the value you entered in **Ramp-down** will carry over.
126130

127-
#### [Personal host pools](#tab/personal-autoscale)
131+
#### Personal host pools
128132

129133
In each phase of the schedule, define whether VMs should be deallocated based on the user session state.
130134

@@ -180,10 +184,142 @@ Now that you've assigned the *Desktop Virtualization Power On Off Contributor* r
180184
> [!NOTE]
181185
> If you change resource settings on other tabs after creating tags, your tags will be automatically updated.
182186
183-
1. Once you're done, go to the **Review + create** tab and select **Create** to deploy your host pool.
187+
1. Once you're done, go to the **Review + create** tab and select **Create** to create and assign your scaling plan to the host pools you selected.
188+
189+
### [PowerShell](#tab/powershell)
190+
191+
Here's how to create a scaling plan using the Az.DesktopVirtualization PowerShell module. The following examples show you how to create a scaling plan and scaling plan schedule.
192+
193+
> [!IMPORTANT]
194+
> In the following examples, you'll need to change the `<placeholder>` values for your own.
195+
196+
[!INCLUDE [include-cloud-shell-local-powershell](includes/include-cloud-shell-local-powershell.md)]
197+
198+
2. Create a scaling plan for your pooled or personal host pool(s) using the [New-AzWvdScalingPlan](/powershell/module/az.desktopvirtualization/new-azwvdscalingplan) cmdlet:
199+
200+
```azurepowershell
201+
$scalingPlanParams = @{
202+
ResourceGroupName = '<resourceGroup>'
203+
Name = '<scalingPlanName>'
204+
Location = '<AzureRegion>'
205+
Description = '<Scaling plan description>'
206+
FriendlyName = '<Scaling plan friendly name>'
207+
HostPoolType = '<Pooled or personal>'
208+
TimeZone = '<Time zone, such as Pacific Standard Time>'
209+
HostPoolReference = @(@{'hostPoolArmPath' = '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/<resourceGroup/providers/Microsoft.DesktopVirtualization/hostPools/<hostPoolName>'; 'scalingPlanEnabled' = $true;})
210+
}
211+
212+
$scalingPlan = New-AzWvdScalingPlan @scalingPlanParams
213+
```
214+
215+
216+
217+
218+
3. Create a scaling plan schedule.
219+
220+
* For pooled host pools, use the [New-AzWvdScalingPlanPooledSchedule](/powershell/module/az.desktopvirtualization/new-azwvdscalingplanpooledschedule) cmdlet. This example creates a pooled scaling plan that runs on Monday through Friday, ramps up at 6:30 AM, starts peak hours at 8:30 AM, ramps down at 4:00 PM, and starts off-peak hours at 10:45 PM.
221+
222+
223+
```azurepowershell
224+
$scalingPlanPooledScheduleParams = @{
225+
ResourceGroupName = 'resourceGroup'
226+
ScalingPlanName = 'scalingPlanPooled'
227+
ScalingPlanScheduleName = 'pooledSchedule1'
228+
DaysOfWeek = 'Monday','Tuesday','Wednesday','Thursday','Friday'
229+
RampUpStartTimeHour = '6'
230+
RampUpStartTimeMinute = '30'
231+
RampUpLoadBalancingAlgorithm = 'BreadthFirst'
232+
RampUpMinimumHostsPct = '20'
233+
RampUpCapacityThresholdPct = '20'
234+
PeakStartTimeHour = '8'
235+
PeakStartTimeMinute = '30'
236+
PeakLoadBalancingAlgorithm = 'DepthFirst'
237+
RampDownStartTimeHour = '16'
238+
RampDownStartTimeMinute = '0'
239+
RampDownLoadBalancingAlgorithm = 'BreadthFirst'
240+
RampDownMinimumHostsPct = '20'
241+
RampDownCapacityThresholdPct = '20'
242+
RampDownForceLogoffUser:$true
243+
RampDownWaitTimeMinute = '30'
244+
RampDownNotificationMessage = '"Log out now, please."'
245+
RampDownStopHostsWhen = 'ZeroSessions'
246+
OffPeakStartTimeHour = '22'
247+
OffPeakStartTimeMinute = '45'
248+
OffPeakLoadBalancingAlgorithm = 'DepthFirst'
249+
}
250+
251+
$scalingPlanPooledSchedule = New-AzWvdScalingPlanPooledSchedule @scalingPlanPooledScheduleParams
252+
```
253+
254+
255+
* For personal host pools, use the [New-AzWvdScalingPlanPersonalSchedule](/powershell/module/az.desktopvirtualization/new-azwvdscalingplanpersonalschedule) cmdlet. The following example creates a personal scaling plan that runs on Monday, Tuesday, and Wednesday, ramps up at 6:00 AM, starts peak hours at 8:15 AM, ramps down at 4:30 PM, and starts off-peak hours at 6:45 PM.
256+
257+
258+
```azurepowershell
259+
$scalingPlanPersonalScheduleParams = @{
260+
ResourceGroupName = 'resourceGroup'
261+
ScalingPlanName = 'scalingPlanPersonal'
262+
ScalingPlanScheduleName = 'personalSchedule1'
263+
DaysOfWeek = 'Monday','Tuesday','Wednesday'
264+
RampUpStartTimeHour = '6'
265+
RampUpStartTimeMinute = '0'
266+
RampUpAutoStartHost = 'WithAssignedUser'
267+
RampUpStartVMOnConnect = 'Enable'
268+
RampUpMinutesToWaitOnDisconnect = '30'
269+
RampUpActionOnDisconnect = 'Deallocate'
270+
RampUpMinutesToWaitOnLogoff = '3'
271+
RampUpActionOnLogoff = 'Deallocate'
272+
PeakStartTimeHour = '8'
273+
PeakStartTimeMinute = '15'
274+
PeakStartVMOnConnect = 'Enable'
275+
PeakMinutesToWaitOnDisconnect = '10'
276+
PeakActionOnDisconnect = 'Hibernate'
277+
PeakMinutesToWaitOnLogoff = '15'
278+
PeakActionOnLogoff = 'Deallocate'
279+
RampDownStartTimeHour = '16'
280+
RampDownStartTimeMinute = '30'
281+
RampDownStartVMOnConnect = 'Disable'
282+
RampDownMinutesToWaitOnDisconnect = '10'
283+
RampDownActionOnDisconnect = 'None'
284+
RampDownMinutesToWaitOnLogoff = '15'
285+
RampDownActionOnLogoff = 'Hibernate'
286+
OffPeakStartTimeHour = '18'
287+
OffPeakStartTimeMinute = '45'
288+
OffPeakStartVMOnConnect = 'Disable'
289+
OffPeakMinutesToWaitOnDisconnect = '10'
290+
OffPeakActionOnDisconnect = 'Deallocate'
291+
OffPeakMinutesToWaitOnLogoff = '15'
292+
OffPeakActionOnLogoff = 'Deallocate'
293+
}
294+
295+
$scalingPlanPersonalSchedule = New-AzWvdScalingPlanPersonalSchedule @scalingPlanPersonalScheduleParams
296+
```
297+
298+
>[!NOTE]
299+
> We recommended that `RampUpStartVMOnConnect` is enabled for the ramp up phase of the schedule if you opt out of having autoscale start session host VMs. For more information, see [Start VM on Connect](start-virtual-machine-connect.md).
300+
301+
4. Use [Get-AzWvdScalingPlan](/powershell/module/az.desktopvirtualization/get-azwvdscalingplan) to get the host pool(s) that your scaling plan is assigned to.
302+
303+
```azurepowershell
304+
$params = @{
305+
ResourceGroupName = 'resourceGroup'
306+
Name = 'scalingPlanPersonal'
307+
}
308+
309+
(Get-AzWvdScalingPlan @params).HostPoolReference | FL HostPoolArmPath,ScalingPlanEnabled
310+
```
311+
312+
313+
You have now created a new scaling plan, 1 or more schedules, assigned it to your pooled or personal host pool(s), and enabled autoscale.
314+
315+
316+
317+
---
184318

185319
## Edit an existing scaling plan
186320

321+
### [Portal](#tab/portal)
322+
187323
To edit an existing scaling plan:
188324

189325
1. Sign in to the [Azure portal](https://portal.azure.com).
@@ -198,45 +334,104 @@ To edit an existing scaling plan:
198334

199335
1. To edit the plan's friendly name, description, time zone, or exclusion tags, go to the **Properties** tab.
200336

337+
### [PowerShell](#tab/powershell)
338+
339+
Here's how to update a scaling plan using the Az.DesktopVirtualization PowerShell module. The following examples show you how to update a scaling plan and scaling plan schedule.
340+
341+
* Update a scaling plan using [Update-AzWvdScalingPlan](/powershell/module/az.desktopvirtualization/update-azwvdscalingplan). This example updates the scaling plan's timezone.
342+
343+
```azurepowershell
344+
$scalingPlanParams = @{
345+
ResourceGroupName = 'resourceGroup'
346+
Name = 'scalingPlanPersonal'
347+
Timezone = 'Eastern Standard Time'
348+
}
349+
350+
Update-AzWvdScalingPlan @scalingPlanParams
351+
```
352+
353+
* Update a scaling plan schedule using [Update-AzWvdScalingPlanPersonalSchedule](/powershell/module/az.desktopvirtualization/update-azwvdscalingplanpersonalschedule). This example updates the ramp up start time.
354+
355+
```azurepowershell
356+
$scalingPlanPersonalScheduleParams = @{
357+
ResourceGroupName = 'resourceGroup'
358+
ScalingPlanName = 'scalingPlanPersonal'
359+
ScalingPlanScheduleName = 'personalSchedule1'
360+
RampUpStartTimeHour = '5'
361+
RampUpStartTimeMinute = '30'
362+
}
363+
364+
Update-AzWvdScalingPlanPersonalSchedule @scalingPlanPersonalScheduleParams
365+
```
366+
367+
368+
---
369+
201370
## Assign scaling plans to existing host pools
202371
203-
You can assign a scaling plan to any existing host pools in your deployment. When you assign a scaling plan to your host pool, the plan will apply to all session hosts within that host pool. The scaling plan also automatically applies to any new session hosts you create in the assigned host pool.
372+
You can assign a scaling plan to any existing host pools of the same type in your deployment. When you assign a scaling plan to your host pool, the plan will apply to all session hosts within that host pool. The scaling plan also automatically applies to any new session hosts you create in the assigned host pool.
204373
205374
If you disable a scaling plan, all assigned resources will remain in the state they were in at the time you disabled it.
206375
207-
### Assign a scaling plan to a single existing host pool
208-
To assign a scaling plan to an existing host pool:
376+
### [Portal](#tab/portal)
377+
378+
To assign a scaling plan to existing host pools:
209379
210380
1. Open the [Azure portal](https://portal.azure.com).
211381
212382
1. In the search bar, type *Azure Virtual Desktop* and select the matching service entry.
213383
214-
1. Select **Host pools**, and select the host pool you want to assign the scaling plan to.
384+
1. Select **Scaling plans**, and select the scaling plan you want to assign to host pools.
215385
216-
1. Under the **Settings** heading, select **Scaling plan**, and then select **+ Assign**. Select the scaling plan you want to assign and select **Assign**. The scaling plan must be in the same Azure region as the host pool and the scaling plan's host pool type must match the type of host pool that you're trying to assign it to.
386+
1. Under the **Manage** heading, select **Host pool assignments**, and then select **+ Assign**. Select the host pools you want to assign the scaling plan to and select **Assign**. The host pools must be in the same Azure region as the scaling plan and the scaling plan's host pool type must match the type of host pools you're trying to assign it to.
217387
218388
> [!TIP]
219389
> If you've enabled the scaling plan during deployment, then you'll also have the option to disable the plan for the selected host pool in the **Scaling plan** menu by unselecting the **Enable autoscale** checkbox, as shown in the following screenshot.
220390
>
221391
> [!div class="mx-imgBorder"]
222392
> ![A screenshot of the scaling plan window. The "enable autoscale" check box is selected and highlighted with a red border.](media/enable-autoscale.png)
223393
224-
### Assign a scaling plan to multiple existing host pools
394+
### [PowerShell](#tab/powershell)
225395
226-
To assign a scaling plan to multiple existing host pools at the same time:
396+
1. Assign a scaling plan to existing host pools using [Update-AzWvdScalingPlan](/powershell/module/az.desktopvirtualization/update-azwvdscalingplan). The following example assigns a personal scaling plan to two existing personal host pools.
227397
228-
1. Open the [Azure portal](https://portal.azure.com).
398+
```azurepowershell
399+
$scalingPlanParams = @{
400+
ResourceGroupName = 'resourceGroup'
401+
Name = 'scalingPlanPersonal'
402+
HostPoolReference = @(
403+
@{
404+
'hostPoolArmPath' = '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup/providers/Microsoft.DesktopVirtualization/hostPools/scalingPlanPersonal';
405+
'scalingPlanEnabled' = $true;
406+
},
407+
@{
408+
'hostPoolArmPath' = '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup/providers/Microsoft.DesktopVirtualization/hostPools/scalingPlanPersonal2';
409+
'scalingPlanEnabled' = $true;
410+
}
411+
)
412+
}
413+
414+
$scalingPlan = Update-AzWvdScalingPlan @scalingPlanParams
415+
```
229416
230-
1. In the search bar, type *Azure Virtual Desktop* and select the matching service entry.
417+
2. Use [Get-AzWvdScalingPlan](/powershell/module/az.desktopvirtualization/get-azwvdscalingplan) to get the host pool(s) that your scaling plan is assigned to.
231418
232-
1. Select **Scaling plans**, and select the scaling plan you want to assign to host pools.
419+
```azurepowershell
420+
$params = @{
421+
ResourceGroupName = 'resourceGroup'
422+
Name = 'scalingPlanPersonal'
423+
}
424+
425+
(Get-AzWvdScalingPlan @params).HostPoolReference | FL HostPoolArmPath,ScalingPlanEnabled
426+
```
427+
428+
---
233429
234-
1. Under the **Manage** heading, select **Host pool assignments**, and then select **+ Assign**. Select the host pools you want to assign the scaling plan to and select **Assign**. The host pools must be in the same Azure region as the scaling plan and the scaling plan's host pool type must match the type of host pools you're trying to assign it to.
235430
236431
## Next steps
237432
238433
Now that you've created your scaling plan, here are some things you can do:
239434
240435
- [Enable diagnostics for your scaling plan](autoscale-diagnostics.md)
241436
242-
If you'd like to learn more about terms used in this article, check out our [autoscale glossary](autoscale-glossary.md). For examples of how autoscale works, see [Autoscale example scenarios](autoscale-scenarios.md). You can also look at our [Autoscale FAQ](autoscale-faq.yml) if you have other questions.
437+
If you'd like to learn more about terms used in this article, check out our [autoscale glossary](autoscale-glossary.md). For examples of how autoscale works, see [Autoscale example scenarios](autoscale-scenarios.md). You can also look at our [Autoscale FAQ](autoscale-faq.yml) if you have other questions.

0 commit comments

Comments
 (0)