Skip to content

Commit f9185a5

Browse files
Merge pull request #263415 from SnehaSudhirG/17Jan-SchedpatchingUpdate
Updated the PS script for Win and Linux machines
2 parents 0b05d1b + fb88578 commit f9185a5

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

articles/update-manager/prerequsite-for-schedule-patching.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Configure schedule patching on Azure VMs for business continuity
33
description: The article describes the new prerequisites to configure scheduled patching to ensure business continuity in Azure Update Manager.
44
ms.service: azure-update-manager
5-
ms.date: 09/18/2023
5+
ms.date: 01/17/2024
66
ms.topic: conceptual
77
author: snehasudhirG
88
ms.author: sudhirsneha
@@ -147,10 +147,47 @@ PATCH on `/subscriptions/subscription_id/resourceGroups/myResourceGroup/provider
147147
}
148148
}
149149
```
150+
# [PowerShell](#tab/new-prereq-powershell)
151+
152+
## Prerequisites
153+
154+
- Patch mode = `AutomaticByPlatform`
155+
- `BypassPlatformSafetyChecksOnUserSchedule` = TRUE
156+
157+
### Enable on Windows VMs
158+
159+
```powershell-interactive
160+
$VirtualMachine = Get-AzVM -ResourceGroupName "<resourceGroup>" -Name "<vmName>"
161+
Set-AzVMOperatingSystem -VM $VirtualMachine -Windows -PatchMode "AutomaticByPlatform"
162+
$AutomaticByPlatformSettings = $VirtualMachine.OSProfile.WindowsConfiguration.PatchSettings.AutomaticByPlatformSettings
163+
164+
if ($null -eq $AutomaticByPlatformSettings) {
165+
$VirtualMachine.OSProfile.WindowsConfiguration.PatchSettings.AutomaticByPlatformSettings = New-Object -TypeName Microsoft.Azure.Management.Compute.Models.WindowsVMGuestPatchAutomaticByPlatformSettings -Property @{BypassPlatformSafetyChecksOnUserSchedule = $true}
166+
} else {
167+
$AutomaticByPlatformSettings.BypassPlatformSafetyChecksOnUserSchedule = $true
168+
}
169+
170+
Update-AzVM -VM $VirtualMachine -ResourceGroupName "<resourceGroup>"
171+
```
172+
### Enable on Linux VMs
173+
174+
```powershell-interactive
175+
$VirtualMachine = Get-AzVM -ResourceGroupName "<resourceGroup>" -Name "<vmName>"
176+
Set-AzVMOperatingSystem -VM $VirtualMachine -Linux -PatchMode "AutomaticByPlatform"
177+
$AutomaticByPlatformSettings = $VirtualMachine.OSProfile.LinuxConfiguration.PatchSettings.AutomaticByPlatformSettings
178+
179+
if ($null -eq $AutomaticByPlatformSettings) {
180+
$VirtualMachine.OSProfile.LinuxConfiguration.PatchSettings.AutomaticByPlatformSettings = New-Object -TypeName Microsoft.Azure.Management.Compute.Models.LinuxVMGuestPatchAutomaticByPlatformSettings -Property @{BypassPlatformSafetyChecksOnUserSchedule = $true}
181+
} else {
182+
$AutomaticByPlatformSettings.BypassPlatformSafetyChecksOnUserSchedule = $true
183+
}
184+
185+
Update-AzVM -VM $VirtualMachine -ResourceGroupName "<resourceGroup>"
186+
```
150187
---
151188

152189
> [!NOTE]
153-
> Currently, you can only enable the new prerequisite for schedule patching via the Azure portal and the REST API. It can't be enabled via the Azure CLI or PowerShell.
190+
> Currently, you can only enable the new prerequisite for schedule patching via the Azure portal, REST API, and PowerShell. It can't be enabled via the Azure CLI.
154191
155192
## Enable automatic guest VM patching on Azure VMs
156193

0 commit comments

Comments
 (0)