Share via

Executable Powershell script that will assist me in removing the Microsoft Monitoring Agent extension from virtual machines given in an Azure subscription.

Anonymous
2023-07-22T06:05:44+00:00

It is a laborious task to remove the legacy extension by logging into each individual VM because I have more than 500 in my subscription.

Windows for home | Windows 11 | Input and language

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. DaveM121 891.1K Reputation points Independent Advisor
    2023-07-22T06:38:04+00:00

    Hi Vikram,

    I am Dave, I will help you with this.

    I apologize, Community is just a consumer forum, due to the scope of your question can you please post this question to our sister forum on Microsoft Q&A (The System Administrators and IT Pro Frum)

    Over there you will have access to a host of System Administrators and IT Pro experts and will get a knowledgeable and quick answer to this question.

    https://docs.microsoft.com/en-us/answers/index....

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2023-07-22T06:08:27+00:00

    I have tried the below script throwing me an Error. But the Resource group still Exists

    #Connect to Azure

    Connect-AzAccount

    #Specify the subscription ID

    $subscriptionId = "xxxxxxxxxxxxxx"

    #Get the list of virtual machines in the subscription

    $vms = Get-AzVM -Status -ResourceGroupName "rg-aspera-dev-01"

    #Loop through each virtual machine and remove the Microsoft Monitoring Agent extension

    foreach ($vm in $vms) {

    Check if the Microsoft Monitoring Agent extension is installed

    if ($vm.Extensions | Where-Object { $.Publisher -eq "Microsoft.EnterpriseCloud.Monitoring" -and $.ExtensionType -eq "MicrosoftMonitoringAgent" }) {

    Remove the Microsoft Monitoring Agent extension

    Remove-AzVMExtension -ResourceGroupName $vm.ResourceGroupName -VMName $vm.Name -Name "MicrosoftMonitoringAgent" -Force

    }

    }

    ERROR:

    ErrorCode: ResourceGroupNotFound

    ErrorMessage: Resource group 'rg-aspera-dev-01' could not be found.

    ErrorTarget:

    StatusCode: 404

    ReasonPhrase: Not Found

    OperationID : 40634be7-1dd1-4aba-9049-280989ec523d

    Was this answer helpful?

    0 comments No comments