Azure Policy for SQL Extension on All VMs

Harry Erbe 20 Reputation points
2025-03-10T21:17:14.15+00:00

Seeking assistance with Azure Policy that applies the SQL Extension to all virtual machines. Currently facing difficulty locating the appropriate policy. Any guidance or examples would be appreciated.

Azure Policy
Azure Policy
An Azure service that is used to implement corporate governance and standards at scale for Azure resources.
970 questions
0 comments No comments
{count} votes

Accepted answer
  1. Naveena Patlolla 975 Reputation points Microsoft External Staff
    2025-03-11T01:04:13.3233333+00:00

    Hi Harry Erbe

    There is no predefined policy definition for this specific SQL extension. To enforce compliance, you will need to create a custom policy.

    please refer below article

    https://learn.microsoft.com/en-us/azure/governance/policy/tutorials/create-custom-policy-definition

    This can be achieved using PowerShell
    I have created PowerShell script to install SQL extensions on multiple VM's

    <#
    .SYNOPSIS
        This script registers SQL Server VMs in Azure by installing the SQL IaaS extension on specified VMs.
       
    .DESCRIPTION
        The script retrieves details of each VM from Azure and registers them as SQL Server VMs.
        It checks for errors such as VM not found, missing properties, or failure during registration.
    .NOTES
      Provide the SQL Server license type as either pay-as-you-go (PAYG) to pay per usage, Azure Hybrid Benefit (AHUB) to use your own license.
        Requirements: Azure PowerShell Module (Az)
    #>
    # List of VM Names to register as SQL VMs
    $vms = @("VM01", "VM02")
    # Loop through each VM
    foreach ($vm in $vms) {
        try {
            # Get the VM details
            $vmDetails = Get-AzVM | Where-Object { $_.Name -eq $vm }
            # Check if VM exists
            if (-not $vmDetails) {
                Write-Host "ERROR: VM '$vm' not found in Azure." -ForegroundColor Red
                continue
            }
            # Attempt to register the VM with SQL IaaS extension
            Write-Host "Registering SQL Server VM: $($vmDetails.Name)..." -ForegroundColor Yellow
            New-AzSqlVM -Name $vmDetails.Name -ResourceGroupName $vmDetails.ResourceGroupName -Location $vmDetails.Location -LicenseType AHUB
            Write-Host "Successfully registered $($vmDetails.Name) as a SQL Server VM." -ForegroundColor Green
        }
        catch {
            Write-Host "ERROR: Failed to register VM '$vm'. Error: $_" -ForegroundColor Red
        }
    }
    

    Please do not forget to "Accept the answer” and “upvote it” wherever the information provided helps you, this can be beneficial to other community members.it would be greatly appreciated and helpful to others.


1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

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.