,

Manage Azure Arc Machine extensions via Powershell

First of all you need to install the module Az.ConnectedMachine

Install-Module Az.ConnectedMachine -AllowClobber

Once the module is installed you can verify your Azure connected machines extension provisioning state by running the following command

  • Replace the variable $_.Name for the name of your machine
  • Replace the variable $_.ResourceGroupName for the name of the resource group where your machine is allocated
Get-AzConnectedMachineExtension -MachineName $_.Name -ResourceGroupName $_.ResourceGroupName

Here it is an example of the results

ResourceGroupName Name                      Location      TypeHandlerVersion ProvisioningState Publisher
----------------- ----                      --------      ------------------ ----------------- ---------
YourResourceGroup AzureMonitorWindowsAgent  YourLocation  1.12.0.0           Succeeded         Microsoft.Azure.Monitor

Sometimes an extension fails to be installed/updated which demands you to uninstall the extension. Here it is an example:

In this case you have the option to manually uninstall the failed extension or to simply running the following command to uninstall at large.

This command will look for all Azure Arc Connected Machines and for each machine found it will remove the extension that has its provisioning state equals failed.

Get-AzConnectedMachine | % { Get-AzConnectedMachineExtension -MachineName $_.Name -ResourceGroupName $_.ResourceGroupName | ? { $_.ProvisioningState -eq "Failed" } | Remove-AzConnectedMachineExtension }

Sometimes, it depends of the amount of failed extensions you have in your environment, this command freezes. To prevent that you can run it as job so it will send the request to remove the failed extension directly to Azure queue without the need to wait for each command to finish.

Get-AzConnectedMachine | % { Get-AzConnectedMachineExtension -MachineName $_.Name -ResourceGroupName $_.ResourceGroupName | ? { $_.ProvisioningState -eq "Failed" } | Remove-AzConnectedMachineExtension -Asjob }

You can follow the queue by looking the Azure Activity log by filtering it by Operation Name Install or Update an Azure Arc extensions


About me

Over 20 years working with IT for multiple fields (logistics, Olympic games, oil and gas, insurance, pharmaceuticals, etc).

Sometimes find solutions on the internet can be challenging. That’s why I decided to create techmission.ca, where I’ll gather some solutions I have to apply on my environments as I receive my “missions” (that’s the way I name client’s requests).

Hope the solutions published here can help you guys as it helps me 🙂

Featured Posts