Skip to content

Commit 7777b0e

Browse files
authored
Merge pull request #96677 from cynthn/maintenance-control-powershell
Maintenance control powershell
2 parents cb59b8e + 4e3c6da commit 7777b0e

File tree

3 files changed

+202
-0
lines changed

3 files changed

+202
-0
lines changed

articles/virtual-machines/linux/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@
341341
items:
342342
- name: CLI
343343
href: ../maintenance-control-cli.md?toc=/azure/virtual-machines/linux/toc.json&bc=/azure/virtual-machines/linux/breadcrumb/toc.json
344+
- name: PowerShell
345+
href: ../maintenance-control-powershell.md?toc=/azure/virtual-machines/linux/toc.json&bc=/azure/virtual-machines/linux/breadcrumb/toc.json
344346
- name: Scheduled events
345347
href: scheduled-events.md
346348
- name: Monitor VMs
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
---
2+
title: Maintenance control for Azure virtual machines using PowerShell
3+
description: Learn how to control when maintenance is applied to your Azure VMs using Maintenance Control and PowerShell.
4+
services: virtual-machines-linux
5+
author: cynthn
6+
7+
ms.service: virtual-machines
8+
ms.topic: article
9+
ms.tgt_pltfrm: vm
10+
ms.workload: infrastructure-services
11+
ms.date: 12/06/2019
12+
ms.author: cynthn
13+
---
14+
15+
# Preview: Control updates with Maintenance Control and Azure PowerShell
16+
17+
Manage platform updates, that don't require a reboot, using maintenance control. Azure frequently updates its infrastructure to improve reliability, performance, security or launch new features. Most updates are transparent to users. Some sensitive workloads, like gaming, media streaming, and financial transactions, can’t tolerate even few seconds of a VM freezing or disconnecting for maintenance. Maintenance control gives you the option to wait on platform updates and apply them within a 35-day rolling window.
18+
19+
Maintenance control lets you decide when to apply updates to your isolated VMs.
20+
21+
With maintenance control, you can:
22+
- Batch updates into one update package.
23+
- Wait up to 35 days to apply updates.
24+
- Automate platform updates for your maintenance window using Azure Functions.
25+
- Maintenance configurations work across subscriptions and resource groups.
26+
27+
> [!IMPORTANT]
28+
> Maintenance Control is currently in public preview.
29+
> This preview version is provided without a service level agreement, and it's not recommended for production workloads. Certain features might not be supported or might have constrained capabilities.
30+
> For more information, see [Supplemental Terms of Use for Microsoft Azure Previews](https://azure.microsoft.com/support/legal/preview-supplemental-terms/).
31+
>
32+
33+
## Limitations
34+
35+
- VMs must be on a [dedicated host](./linux/dedicated-hosts.md), or be created using an [isolated VM size](./linux/isolation.md).
36+
- After 35 days, an update will automatically be applied and availability constraints will not be respected.
37+
- User must have **Resource Owner** access.
38+
39+
40+
## Enable the PowerShell module
41+
42+
Make sure `PowerShellGet` is up to date.
43+
44+
```azurepowershell-interactive
45+
Install-Module -Name PowerShellGet -Repository PSGallery -Force
46+
```
47+
48+
The Az.Maintenance PowerShell cmdlets are in preview, so you need to install the module with the `AllowPrerelease` parameter in Cloud Shell or your local PowerShell installation.
49+
50+
```azurepowershell-interactive
51+
Install-Module -Name Az.Maintenance -AllowPrerelease
52+
```
53+
54+
If you are installing locally, make sure you open your PowerShell prompt as an administrator.
55+
56+
You may also be asked to confirm that you want to install from an *untrusted repository*. Type `Y` or select **Yes to All** to install the module.
57+
58+
59+
60+
## Create a maintenance configuration
61+
62+
Create a resource group as a container for your configuration. In this example, a resource group named *myMaintenanceRG* is created in *eastus*. If you already have a resource group that you want to use, you can skip this part and replace the resource group name with you own in the rest of the examples.
63+
64+
```azurepowershell-interactive
65+
New-AzResourceGroup `
66+
-Location eastus `
67+
-Name myMaintenanceRG
68+
```
69+
70+
Use [New-AzMaintenanceConfiguration](https://docs.microsoft.com/powershell/module/az.maintenance/new-azmaintenanceconfiguration) to create a maintenance configuration. This example creates a maintenance configuration named *myConfig* scoped to the host.
71+
72+
```azurepowershell-interactive
73+
$config = New-AzMaintenanceConfiguration `
74+
-ResourceGroup myMaintenanceRG `
75+
-Name myConfig `
76+
-MaintenanceScope host `
77+
-Location eastus
78+
```
79+
80+
Using `-MaintenanceScope host` ensures that the maintenance configuration is used for controlling updates to the host.
81+
82+
If you try to create a configuration with the same name, but in a different location, you will get an error. Configuration names must be unique to your subscription.
83+
84+
You can query for available maintenance configurations using [Get-AzMaintenanceConfiguration](https://docs.microsoft.com/powershell/module/az.maintenance/get-azmaintenanceconfiguration).
85+
86+
```azurepowershell-interactive
87+
Get-AzMaintenanceConfiguration | Format-Table -Property Name,Id
88+
```
89+
90+
## Assign the configuration
91+
92+
Use [New-AzConfigurationAssignment](https://docs.microsoft.com/powershell/module/az.maintenance/new-azconfigurationassignment) to assign the configuration to your isolated VM or Azure Dedicated Host.
93+
94+
### Isolated VM
95+
96+
Apply the configuration to a VM using the ID of the configuration. Specify `-ResourceType VirtualMachines` and supply the name of the VM for `-ResourceName`, and the resource group of the VM for `-ResourceGroupName`.
97+
98+
```azurepowershell-interactive
99+
New-AzConfigurationAssignment `
100+
-ResourceGroupName myResourceGroup `
101+
-Location eastus `
102+
-ResourceName myVM `
103+
-ResourceType VirtualMachines `
104+
-ProviderName Microsoft.Compute `
105+
-ConfigurationAssignmentName $config.Name `
106+
-MaintenanceConfigurationId $config.Id
107+
```
108+
109+
### Dedicate host
110+
111+
To apply a configuration to a dedicated host, you also need to include `-ResourceType hosts`, `-ResourceParentName` with the name of the host group, and `-ResourceParentType hostGroups`.
112+
113+
114+
```azurepowershell-interactive
115+
New-AzConfigurationAssignment `
116+
-ResourceGroupName myResourceGroup `
117+
-Location eastus `
118+
-ResourceName myHost `
119+
-ResourceType hosts `
120+
-ResourceParentName myHostGroup `
121+
-ResourceParentType hostGroups `
122+
-ProviderName Microsoft.Compute `
123+
-ConfigurationAssignmentName $config.Name `
124+
-MaintenanceConfigurationId $config.Id
125+
```
126+
127+
## Check for pending updates
128+
129+
Use [Get-AzMaintenanceUpdate](https://docs.microsoft.com/powershell/module/az.maintenance/get-azmaintenanceupdate) to see if there are pending updates. Use `-subscription` to specify the Azure subscription of the VM if it is different from the one that you are logged into.
130+
131+
### Isolated VM
132+
133+
Check for pending updates for an isolated VM. In this example, the output is formatted as a table for readability.
134+
135+
```azurepowershell-interactive
136+
Get-AzMaintenanceUpdate `
137+
-ResourceGroupName myResourceGroup `
138+
-ResourceName myVM `
139+
-ResourceType VirtualMachines `
140+
-ProviderName Microsoft.Compute | Format-Table
141+
```
142+
143+
### Dedicated host
144+
145+
To check for pending updates for a dedicated host. In this example, the output is formatted as a table for readability. Replace the values for the resources with your own.
146+
147+
```azurepowershell-interactive
148+
Get-AzMaintenanceUpdate `
149+
-ResourceGroupName myResourceGroup `
150+
-ResourceName myHost `
151+
-ResourceType hosts `
152+
-ResourceParentName myHostGroup `
153+
-ResourceParentType hostGroups `
154+
-ProviderName Microsoft.Compute | Format-Table
155+
```
156+
157+
## Apply updates
158+
159+
Use [New-AzApplyUpdate](https://docs.microsoft.com/powershell/module/az.maintenance/new-azapplyupdate) to apply pending updates.
160+
161+
### Isolated VM
162+
163+
Create a request to apply updates to an isolated VM.
164+
165+
```azurepowershell-interactive
166+
New-AzApplyUpdate `
167+
-ResourceGroupName myResourceGroup `
168+
-ResourceName myVM `
169+
-ResourceType VirtualMachines `
170+
-ProviderName Microsoft.Compute
171+
```
172+
173+
### Dedicated host
174+
175+
Apply updates to a dedicated host.
176+
177+
```azurepowershell-interactive
178+
New-AzApplyUpdate `
179+
-ResourceGroupName myResourceGroup `
180+
-ResourceName myHost `
181+
-ResourceType hosts `
182+
-ResourceParentName myHostGroup `
183+
-ResourceParentType hostGroups `
184+
-ProviderName Microsoft.Compute
185+
```
186+
187+
## Remove a maintenance configuration
188+
189+
Use [Remove-AzMaintenanceConfiguration](https://docs.microsoft.com/powershell/module/az.maintenance/remove-azmaintenanceconfiguration) to delete a maintenance configuration.
190+
191+
```azurecli-interactive
192+
Remove-AzMaintenanceConfiguration `
193+
-ResourceGroupName myResourceGroup `
194+
-Name $config.Name
195+
```
196+
197+
## Next steps
198+
To learn more, see [Maintenance and updates](maintenance-and-updates.md).

articles/virtual-machines/windows/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@
418418
href: ../maintenance-notifications-powershell.md?toc=/azure/virtual-machines/windows/toc.json&bc=/azure/virtual-machines/windows/breadcrumb/toc.json
419419
- name: Maintenance control
420420
items:
421+
- name: PowerShell
422+
href: ../maintenance-control-powershell.md?toc=/azure/virtual-machines/windows/toc.json&bc=/azure/virtual-machines/windows/breadcrumb/toc.json
421423
- name: CLI
422424
href: ../maintenance-control-cli.md?toc=/azure/virtual-machines/windows/toc.json&bc=/azure/virtual-machines/windows/breadcrumb/toc.json
423425
- name: Scheduled events

0 commit comments

Comments
 (0)