{
# set parameters - resource group, server, database and storage account
$params = @{ rgname = "rg";
serverName = "my-server";
databaseName = "my-db";
storageAccount = "mystorage"
}
# Turn on ATP
Enable-AzureRmSqlServerAdvancedThreatProtection -ResourceGroupName $params.rgname -ServerName $params.serverName
# Set Vulnerability Assessment storage settings for all the databases in the server
Get-AzureRmSqlDatabase -ResourceGroupName $params.rgname -ServerName $params.serverName `
| where {$_.DatabaseName -ne "master"} `
| Update-AzureRmSqlDatabaseVulnerabilityAssessmentSettings `
-StorageAccountName $params.storageAccount
# Update vulnerability assessment settings to turn ON recurring scans, and provide email to receive results
$scanNotificationEmail = @(" user1@microsoft.com ")
Get-AzureRmSqlDatabase -ResourceGroupName $params.rgname -ServerName $params.serverName`
| where {$_.DatabaseName -ne "master"} `
| Update-AzureRmSqlDatabaseVulnerabilityAssessmentSettings `
-RecurringScansInterval Weekly `
-NotificationEmail $scanNotificationEmail `
-EmailAdmins $true
# Set Vulnerability Assessment baseline for rule VA1143 on all the databases in the server
$ruleId = "VA1143"
$baselineResult = @( '1')
Get-AzureRmSqlDatabase -ResourceGroupName $params.rgname -ServerName $params.serverName `
| where {$_.DatabaseName -ne "master"} `
| Set-AzureRmSqlDatabaseVulnerabilityAssessmentRuleBaseline `
-RuleId $ruleId `
-BaselineResult $baselineResult
# Run a new scan on a database
$scanId1 = "custom-scan1"
$scanJob = Start-AzureRmSqlDatabaseVulnerabilityAssessmentScan `
-ResourceGroupName $params.rgname `
-ServerName $params.serverName `
-DatabaseName $params.databaseName `
-ScanId $scanId1 `
-AsJob
$scanJob | Wait-Job
$scanRecord = $scanJob | Receive-Job
# Convert the raw scan results to an Excel file
$convertScanResult = Convert-AzureRmSqlDatabaseVulnerabilityAssessmentScan `
-ResourceGroupName $params.rgname `
-ServerName $params.serverName `
-DatabaseName $params.databaseName `
-ScanId $scanId1
# Download the scan results Excel summary file
$connectionStringToStorageAccount = "DefaultEndpointsProtocol=https;AccountName=......."
$convertedScanResultsDownloadLocalFolder = "C:\ScanResults\"
$storageAccountContext = New-AzureStorageContext -ConnectionString $connectionStringToStorageAccount
$convertScanResultSplitted = $convertScanResult.ExportedReportLocation -split "/"
$containerName = $convertScanResultSplitted[3]
Get-AzureStorageBlobContent -Blob ($convertScanResult.ExportedReportLocation -split $containerName + '/')[1] `
-Container $containerName `
-Destination $convertedScanResultsDownloadLocalFolder `
-Context $storageAccountContext
}
Cmdlet | Usage |
Enable-AzureRmSqlServerAdvancedThreatProtection |
Enables Advanced Threat Protection on a server. |
Get-AzureRmSqlServerAdvancedThreatProtectionPolicy |
Gets the Advanced Threat Protection policy of a server. |
Disable-AzureRmSqlServerAdvancedThreatProtection |
Disables Advanced Threat Protection on a server. |
Update-AzureRmSqlDatabaseVulnerabilityAssessmentSettings |
Updates the vulnerability assessment settings of a database |
Get-AzureRmSqlDatabaseVulnerabilityAssessmentSettings |
Returns the vulnerability assessment settings of a database |
Clear-AzureRmSqlDatabaseVulnerabilityAssessmentSettings |
Clear the vulnerability assessment settings of a database |
Set-AzureRmSqlDatabaseVulnerabilityAssessmentRuleBaseline |
Sets the vulnerability assessment rule baseline. |
Get-AzureRmSqlDatabaseVulnerabilityAssessmentRuleBaseline |
Gets the vulnerability assessment rule baseline for a given rule. |
Clear-AzureRmSqlDatabaseVulnerabilityAssessmentRuleBaseline |
Clears the vulnerability assessment rule baseline. First set the baseline before using this cmdlet to clear it. |
Start-AzureRmSqlDatabaseVulnerabilityAssessmentScan |
Triggers the start of a vulnerability assessment scan |
Get-AzureRmSqlDatabaseVulnerabilityAssessmentScanRecord |
Gets all vulnerability assessment scan record(s) associated with a given database. |
Convert-AzureRmSqlDatabaseVulnerabilityAssessmentScan |
Converts vulnerability assessment scan results to an Excel file |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.