Because I am not allowed to enable Microsoft Defender for SQL from Azure Portal, I am tring to find a Powershell or AzureCLI command to enable it from CloudShell. The final step is to use that command in a pipeline. I am expecting to be a command that get as parameters the name of the server and the group and automatically enable the Microsoft Defender for SQL.
I tried this:
az sql server threat-policy update --resource-group <my-resource-group> --server-name <my-sql-server-name> --state Enabled
The answer was:
‘threat-policy’ is misspelled or not recognized by the system.
EDIT
After more investigation I have found a partial solution. I will explain bellow:
- In the first state the status is disabled: "Enabled status: Disabled"
- After I run the following command:
Update-AzSqlServerAdvancedThreatProtectionSetting -Enable $true -ResourceGroupName 'my-resource-group' -ServerName 'my-server-name'
the status was changed to "Enabled status: Enabled at the subscription-level"
and bellow of the status an warning is shown with an "enable" button saying that "SQL Vulnerability Assessment is not configured. Click to enable express configuration".
- I would like to have also the "Vulnerability Assesment" enabled in order to have an overview of the findings. I thought this is part of Microsoft Defender for SQL, and enabled it will enable also the "Voulnerability assesment". Are these different?
2
Answers
I haven’t checked the commands, but their description here in the docs makes me believe that they create and enable Microsoft Defender For SQL. This enables the pricing plan for the entire subscription rather than for an individual resource, as it seems that doing that programmatically might require a POST request to the ARM API.
I have one SQL server named
samplesql28
where Microsoft Defender is currently not enabled as below:Initially, I too got same error when I ran your command in my environment like this:
To enable Microsoft Defender for SQL under subscription level, make use of below CLI command:
Response:
When I checked the same in Portal, Microsoft Defender for SQL enabled successfully as below:
Reference:
Microsoft Defender for SQL – Azure SQL Database