How to Update Azure VM Monitoring Agent?

Update Azure VM Monitoring Agent Both Windows and Linux

use the below PowerShell script to update Microsoft Monitoring Agent (MMA) on Windows Virtual Machine. MMM is also commonly reffered as Ops Manager.

$Subscription = ""
$Settings = @{"workspaceId" = ""}
$ProtectedSettings = @{"workspaceKey" = ""}
$ResourceGroupName = ""
$VMName = ""
$Location = ""

Set-AzContext -SubscriptionName "$Subscription"

Set-AzVMExtension -ExtensionName "MicrosoftMonitoringAgent" `
    -ResourceGroupName $ResourceGroupName `
    -VMName $VMName `
    -Publisher "Microsoft.EnterpriseCloud.Monitoring" `
    -ExtensionType "MicrosoftMonitoringAgent" `
    -TypeHandlerVersion 1.0 `
    -Settings $Settings `
    -ProtectedSettings $ProtectedSettings `
    -Location $Location

Update Azure Monitoring Agent for Linux VM or Servers

use the below PowerShell script to update OMS Monitoring Agent on Azure Linux Virtual Machine.

$Subscription = ""
$Settings = @{"workspaceId" = ""}
$ProtectedSettings = @{"workspaceKey" = ""}
$ResourceGroupName = ""
$VMName = ""
$Location = ""

Set-AzContext -SubscriptionName "$Subscription"

Set-AzVMExtension -ExtensionName "OMSAgentForLinux" `
    -ResourceGroupName $ResourceGroupName `
    -VMName $VMName `
    -Publisher "Microsoft.EnterpriseCloud.Monitoring" `
    -ExtensionType "OmsAgentForLinux" `
    -TypeHandlerVersion 1.14 `
    -Settings $Settings `
    -ProtectedSettings $ProtectedSettings `
    -Location $Location

Azure Monitoring Agent Analysis

KQL Query to find VM Extensions without using Monitor Log Data (Works Universally):

resources
| where type == "microsoft.compute/virtualmachines/extensions"
| where tostring(id) has "<_add_azure_vm_name_>"

KQL Query to find Azure VMs which are having OMS Agent:

resources
| where type == "microsoft.compute/virtualmachines/extensions"
| where tostring(id) != ""
| where name == "OMSAgentForLinux"

KQL Query to find Azure VMs which are having MMA Agent:

resources
| where type == "microsoft.compute/virtualmachines/extensions"
| where tostring(id) != ""
| where name == "MicrosoftMonitoringAgent"

How to find Azure OMS Monitoring Agent and MMA Monitoring Agent information using PowerShell?

Syntax:

Set-AzContext -SubscriptionName "_add_azure_subscription_name_"

Get-AzVM -Name "_add_AzureVM_name_" -ResourceGroup "_add_AzureResourceGroup_name_" | Select -ExpandProperty Extensions | | Where-Object -Property VirtualMachineExtensionType -eq -Value "_add_extension_name_" | Select Name, TypeHandlerVersion

Example: For Linux Monitoring Agent | Azure OMS Linux Agent

Set-AzContext -SubscriptionName "Azure PaaS"

Get-AzVM -Name "VM-Linux-01" -ResourceGroup "dev-pass-eus-rg" | Select -ExpandProperty Extensions | Where-Object -Property VirtualMachineExtensionType -eq -Value "OmsAgentForLinux" | Select Name, TypeHandlerVersion

Example: For Windows Monitoring Agent | Azure MMA Windows Agent

Set-AzContext -SubscriptionName "Azure PaaS"

Get-AzVM -Name "VM-WIN-01" -ResourceGroup "dev-pass-eus-rg" | Select -ExpandProperty Extensions | Where-Object -Property VirtualMachineExtensionType -eq -Value "MicrosoftMonitoringAgent" | Select Name, TypeHandlerVersion

How to find Azure OMS Monitoring Agent or MMA Monitoring Agent information using PowerShell Script?

PowerShell Master Script:

## Define Parameters
$SubscriptionName = ""
$LinuxAgentExtensionName = "OmsAgentForLinux"
$WindowsAgentExtensionName = "MicrosoftMonitoringAgent"
$C = 0

## Switch to Subscription
Set-AzureRmContext -SubscriptionName "$SubscriptionName" | Out-Null

## Fetch all the Azure Resource Groups from Select Subscription
$RGs = Get-AzureRMResourceGroup
foreach ($RG in $RGs) {
    ## Get Azure VMs 
	$VMs = Get-AzureRmVM -ResourceGroupName $RG.ResourceGroupName
	foreach ($VM in $VMs) {
        $C+=1
        Write-Output ("--------------------------------------------------------------------")
	    Write-Output ("Server Count : $C")
        $VMName = $VM.Name
        $ResourceGroupName = $VM.ResourceGroupName
        $Location = $VM.Location
        $OSType = $VM.StorageProfile.OSDisk.OSType
        if($OSType -eq "Linux"){
            Write-Output ("Virtual Machine: $VMName")
            Write-Output ("ResourceGroup  : $ResourceGroupName")
            Write-Output ("Location       : $Location")
            Write-Output ("OSType         : $OSType")
	        Get-AzVM -Name "$VMName" -ResourceGroup "$ResourceGroupName" `
            | Select -ExpandProperty Extensions `
            | Where-Object -Property VirtualMachineExtensionType -eq -Value "$LinuxAgentExtensionName" `
            | Select Name, TypeHandlerVersion
        }
        if($OSType -eq "Windows"){
            Write-Output ("Virtual Machine: $VMName")
            Write-Output ("ResourceGroup  : $ResourceGroupName")
            Write-Output ("Location       : $Location")
            Write-Output ("OSType         : $OSType")
            Get-AzVM -Name "$VMName" -ResourceGroup "$ResourceGroupName" `
            | Select -ExpandProperty Extensions `
            | Where-Object -Property VirtualMachineExtensionType -eq -Value "$WindowsAgentExtensionName" `
            | Select Name, TypeHandlerVersion
        }
	}
}
Write-Output ("--------------------------------------------------------------------")
Write-Output ("Total Number of VMs in Subscription: $SubscriptionName : $C")
Write-Output ("--------------------------------------------------------------------")