Last active
May 4, 2024 20:58
-
-
Save SvenAelterman/9f9aa1fa66cea3f7484171e6cef0e2c6 to your computer and use it in GitHub Desktop.
Removes a specified extension from all Arc-enabled machines in a resource group
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A PowerShell script using the Az PowerShell module to remove a specific extension WindowsPatchExtension from all Azure Arc enabled machines in a specific resource group. | |
# The script will remove the extension from all machines in the resource group, regardless of the extension status. | |
# Parameters | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory = $true)] | |
[string] $ResourceGroupName, | |
[Parameter()] | |
[string] $ExtensionName = "WindowsPatchExtension" | |
) | |
# Connect to Azure | |
#Connect-AzAccount | |
# Get all Azure Arc enabled servers in the resource group | |
$arcMachines = Get-AzResource -ResourceGroupName $ResourceGroupName | Where-Object { $_.Type -eq "Microsoft.HybridCompute/machines" } | |
# Remove the extension from all machines | |
foreach ($arcMachine in $arcMachines) { | |
$machineName = $arcMachine.Name | |
Write-Output "Removing extension $ExtensionName from machine $machineName" | |
Remove-AzResource -ResourceId "$($arcMachine.ResourceId)/extensions/$ExtensionName" -Force -WhatIf:$WhatIfPreference | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment