Skip to content

Commit bc1bce4

Browse files
authored
Return objects
1 parent e2341c8 commit bc1bce4

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

articles/virtual-machines/maintenance-notifications-powershell.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,11 @@ function MaintenanceIterator {
7171
$vmList = Get-AzVM -ResourceGroupName $rg.ResourceGroupName
7272
foreach ($vm in $vmList) {
7373
$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
8079
}
8180
}
8281
}
@@ -89,7 +88,11 @@ function MaintenanceIterator {
8988
Using information from the function in the previous section, the following starts maintenance on a VM if **IsCustomerInitiatedMaintenanceAllowed** is set to true.
9089

9190
```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+
9396
```
9497

9598
## Classic deployments

0 commit comments

Comments
 (0)