Share via

How to enable SQL best practices assessments for SQL VMs via Powershell (not CLI)

Paul Sebestyen 0 Reputation points
2025-10-21T18:27:00.6333333+00:00

I am using Powershell and the Update-AzSqlVM cmdlet to enable the features included with the SQL Server IaaS extension. I have been able to successfully Configure Storage via -SqlManagementType 'Full' parameter, but having trouble with the Enable SQL best practices assessments option. Looking at the help, it would appear that -AssessmentSettingEnable is the parameter to use for this. However, there is a required Log Analytics workspace name in the configuration. I do not see an option for this in the help. Running the cmdlet with the -AssessmentSettingEnable switch parameter does not produce an error, but it does not enable this as expected either. Any help would be greatly appreciated.

SQL Server on Azure Virtual Machines
0 comments No comments

2 answers

Sort by: Most helpful
  1. Paul Sebestyen 0 Reputation points
    2025-11-19T14:13:52.5666667+00:00

    TL;DR - This cannot be done with just powershell at this time.


  2. Anonymous
    2025-10-21T20:48:41.41+00:00

    Hi Paul Sebestyen
    Welcome to the Microsoft Q&A Platform.
    Turning on “SQL best practices assessments” needs two things: (1) the toggle and (2) a Log Analytics workspace to land the results. The switch alone won’t light it up, and the parameter is plural: -AssessmentSettingsEnable. Depending on your Az module version, PowerShell may or may not expose a workspace parameter; if it doesn’t, use one Azure CLI line from your PowerShell session to attach the workspace once.

    here’s a clean, copy-paste path you can choose from.

    1. easiest (run in PowerShell, calls Azure CLI once)

    This attaches the workspace and sets a schedule; then you can trigger an immediate run with PowerShell.

    # If 'az sql vm' isn't available:
    # az extension add --name sqlvm
    
    # Attach workspace and set a weekly schedule (example: Mondays 23:00 local)
    az sql vm update `
      -g <rg> -n <sqlVmName> `
      --enable-assessment true `
      --workspace-name <laWorkspaceName> `
      --workspace-rg <laWorkspaceRg> `
      --assessment-day-of-week Monday `
      --assessment-weekly-interval 1 `
      --assessment-start-time-local "23:00"
    
    # (Optional) kick off a run right now from PowerShell:
    Update-AzSqlVM -ResourceGroupName <rg> -Name <sqlVmName> -AssessmentSettingRunImmediately
    

    pure PowerShell when your module exposes workspace parameter (Some Az.SqlVirtualMachine versions do. If you have it, use this.)

    # Get LA workspace resourceId
    $ws   = Get-AzOperationalInsightsWorkspace -ResourceGroupName "<laWorkspaceRg>" -Name "<laWorkspaceName>"
    $wsId = $ws.ResourceId
    
    # Enable assessment + bind workspace
    Update-AzSqlVM `
      -ResourceGroupName "<rg>" `
      -Name "<sqlVmName>" `
      -AssessmentSettingsEnable $true `
      -AssessmentSettingsWorkspaceResourceId $wsId
    
    # (Optional) schedule weekly and/or run once immediately
    Update-AzSqlVM -ResourceGroupName "<rg>" -Name "<sqlVmName>" `
      -ScheduleEnable -ScheduleDayOfWeek Monday -ScheduleWeeklyInterval 1 -ScheduleStartTime "23:00"
    Update-AzSqlVM -ResourceGroupName "<rg>" -Name "<sqlVmName>" -AssessmentSettingRunImmediately
    

    pure PowerShell when the workspace parameter isn’t available (“Wire up” ingestion yourself, then use the existing switches.)

    Ensure SQL IaaS extension is in Full mode (you already set -SqlManagementType Full).

    Install/verify Azure Monitor Agent (AMA) on the VM:

    Set-AzVMExtension -ResourceGroupName <rg> -VMName <vm> -Location <location> `
      -Publisher "Microsoft.Azure.Monitor" -ExtensionType "AzureMonitorWindowsAgent" `
      -Name "AzureMonitorWindowsAgent" -TypeHandlerVersion "1.10" -EnableAutomaticUpgrade $true
    

    Create/choose a Log Analytics workspace; capture its ResourceId to $wsId.

    Create a Data Collection Rule that ingests the SQL Assessment output (custom text logs) and associate it to the VM and workspace:

    # sketch only – fill in inputs for New-AzDataCollectionRule and New-AzDataCollectionRuleAssociation
    New-AzDataCollectionRule ...
    New-AzDataCollectionRuleAssociation ...
    

    Then enable/schedule with:

    Update-AzSqlVM -ResourceGroupName <rg> -Name <sqlVmName> -AssessmentSettingsEnable $true
    Update-AzSqlVM -ResourceGroupName <rg> -Name <sqlVmName> -ScheduleEnable -ScheduleDayOfWeek Monday -ScheduleWeeklyInterval 1 -ScheduleStartTime "23:00"
    

    why your previous command didn’t work

    -AssessmentSettingEnable → the correct switch is plural: -AssessmentSettingsEnable.

    A workspace is mandatory. Without attaching one, the toggle alone won’t produce results.

    Some Az.SqlVirtualMachine versions don’t expose a workspace parameter; that’s why the CLI route works immediately.

    pre-checks (quick)

    SQL IaaS extension state: Healthy, mode = Full.

    VM has outbound 443 to Azure Monitor/Log Analytics endpoints.

    Role: you (or the VM’s managed identity) can write to the chosen workspace.

    Keep Az modules current (Get-Module Az.SqlVirtualMachine -List | select Name,Version).

    how to verify it’s really enabled

    Portal: SQL VM → “SQL best practices assessments” shows Enabled; runs start appearing.

    Log Analytics: after a run, query for results (first run may take a bit):

    SqlAssessment_CL
    | take 10
    
    
    

    Learn --> https://dori-uw-1.kuma-moon.com/en-us/azure/azure-sql/virtual-machines/windows/sql-assessment-for-sql-vm?view=azuresql&tabs=azure-portal


Your answer

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