List all vm 'extensions' used across azure tenant(across multiple VMs)

Neena Sharma 25 Reputation points
2023-07-02T08:05:00.49+00:00

Hello Community,

I came across this Azure Built in Policy: (Compute section under Policy)

Only approved VM extensions should be installed

In order to prepare and apply this in my production environment, I infer that we have the following command to list all AVAILABLE extensions in a particular region ie eastus below(across Windows and Linux VMs):

az vm extension image list --location eastus --output table

Ref: here and here

But,in order to know what extensions are currently in use, do we have any command to check this(across tenant VMs)?

The below command mandatorily requires a particular RG and VM name:

`az vm extension list --vm-name

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
8,229 questions
0 comments No comments
{count} votes

Accepted answer
  1. Luke Murray 11,246 Reputation points MVP
    2023-07-02T08:28:45.13+00:00

    I don't believe theres a CLI or PowerShell command to do that directory, however, this PowerShell script will look through all your Virtual Machines and export the extensions to a table:

    # Connect to Azure
    Connect-AzAccount
    
    # Get all virtual machines
    $vms = Get-AzVM
    
    # Create an array to store the extension data
    $extensionData = @()
    
    # Loop through each virtual machine and get its extensions
    foreach ($vm in $vms) {
        $vmName = $vm.Name
        $resourceGroup = $vm.ResourceGroupName
        $extensions = Get-AzVMExtension -ResourceGroupName $resourceGroup -VMName $vmName
        foreach ($extension in $extensions) {
            $extensionData += [PSCustomObject]@{
                VirtualMachine = $vmName
                ExtensionName = $extension.Name
                Publisher = $extension.Publisher
                Version = $extension.Version
                ProvisioningState = $extension.ProvisioningState
            }
        }
    }
    
    # Display the extension data in a table
    $extensionData | Format-Table -AutoSize
    
    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.