Skip to content

Latest commit

 

History

History
56 lines (42 loc) · 3.12 KB

sql-database-auditing-and-threat-detection-powershell.md

File metadata and controls

56 lines (42 loc) · 3.12 KB

title: PowerShell example-auditing-threat detection-Azure SQL Database | Microsoft Docs description: Azure PowerShell example script to configure auditing & threat detection in an Azure SQL Database services: sql-database ms.service: sql-database ms.subservice: threat-detection ms.custom: security ms.devlang: PowerShell ms.topic: sample author: ronitr ms.author: ronitr ms.reviewer: carlrab manager: craigg ms.date: 09/07/2018

Use PowerShell to configure SQL Database auditing and threat detection

This PowerShell script example configures SQL Database auditing and threat detection.

[!INCLUDE quickstarts-free-trial-note] [!INCLUDE cloud-shell-powershell.md]

If you choose to install and use the PowerShell locally, this tutorial requires the Azure PowerShell module version 5.7.0 or later. Run Get-Module -ListAvailable AzureRM to find the version. If you need to upgrade, see Install Azure PowerShell module. If you are running PowerShell locally, you also need to run Connect-AzureRmAccount to create a connection with Azure.

Sample script

[!code-powershell-interactivemain]

Clean up deployment

After the script sample has been run, the following command can be used to remove the resource group and all resources associated with it.

Remove-AzureRmResourceGroup -ResourceGroupName $resourcegroupname

Script explanation

This script uses the following commands. Each command in the table links to command specific documentation.

Command Notes
New-AzureRmResourceGroup Creates a resource group in which all resources are stored.
New-AzureRmSqlServer Creates a logical server that hosts a database or elastic pool.
New-AzureRmSqlDatabase Creates a database in a logical server as a single or a pooled database.
New-AzureRmStorageAccount Creates a Storage account.
Set-AzureRmSqlDatabaseAuditingPolicy Sets the auditing policy for a database.
Set-AzureRmSqlDatabaseThreatDetectionPolicy Sets a threat detection policy on a database.
Remove-AzureRmResourceGroup Deletes a resource group including all nested resources.

Next steps

For more information on the Azure PowerShell, see Azure PowerShell documentation.

Additional SQL Database PowerShell script samples can be found in the Azure SQL Database PowerShell scripts.