File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed
articles/virtual-machines Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -71,12 +71,11 @@ function MaintenanceIterator {
71
71
$vmList = Get-AzVM -ResourceGroupName $rg.ResourceGroupName
72
72
foreach ($vm in $vmList) {
73
73
$vmDetails = Get-AzVM -ResourceGroupName $rg.ResourceGroupName -Name $vm.Name -Status
74
- if ($vmDetails.MaintenanceRedeployStatus) {
75
- Write-Output -InputObject @{
76
- VMName = $vmDetails.Name
77
- IsCustomerInitiatedMaintenanceAllowed = $vmDetails.MaintenanceRedeployStatus.IsCustomerInitiatedMaintenanceAllowed
78
- LastOperationMessage = $vmDetails.MaintenanceRedeployStatus.LastOperationMessage
79
- }
74
+ [pscustomobject]@{
75
+ Name = $vmDetails.Name
76
+ ResourceGroupName = $rg.ResourceGroupName
77
+ IsCustomerInitiatedMaintenanceAllowed = [bool]$vmDetails.MaintenanceRedeployStatus.IsCustomerInitiatedMaintenanceAllowed
78
+ LastOperationMessage = $vmDetails.MaintenanceRedeployStatus.LastOperationMessage
80
79
}
81
80
}
82
81
}
@@ -89,7 +88,11 @@ function MaintenanceIterator {
89
88
Using information from the function in the previous section, the following starts maintenance on a VM if ** IsCustomerInitiatedMaintenanceAllowed** is set to true.
90
89
91
90
``` powershell
92
- Restart-AzVM -PerformMaintenance -name $vm.Name -ResourceGroupName $rg.ResourceGroupName
91
+
92
+ MaintenanceIterator -SubscriptionId <Subscription ID> |
93
+ Where-Object -FilterScript {$_.IsCustomerMaintenanceAllowed} |
94
+ Restart-AzVM -PerformMaintenance
95
+
93
96
```
94
97
95
98
## Classic deployments
You can’t perform that action at this time.
0 commit comments