Skip to content

Instantly share code, notes, and snippets.

@dazfuller
Last active January 13, 2017 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dazfuller/be132cc19728d9de428bdf26b106928d to your computer and use it in GitHub Desktop.
Save dazfuller/be132cc19728d9de428bdf26b106928d to your computer and use it in GitHub Desktop.
<#
.DESCRIPTION
Enables Transparent Data Encryption on all Azure SQL Databases within a subscription
.NOTES
AUTHOR: @dazfuller
LASTEDIT: Jan 12, 2017
#>
$connectionName = "AzureRunAsConnection"
try
{
$servicePrincipalConnection = Get-AutomationConnection -Name $connectionName
"Logging into Azure..."
Login-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
}
catch
{
if (!$servicePrincipalConnection)
{
$errorMessage = "Connection $connectionName not found."
throw $errorMessage
}
else
{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
Get-AzureRmResourceGroup `
| Get-AzureRmSqlServer `
| Get-AzureRmSqlDatabase `
| Where-Object -FilterScript { $_.DatabaseName -ne "master" } `
| Get-AzureRmSqlDatabaseTransparentDataEncryption `
| Where-Object -FilterScript { $_.State -ne "Enabled" } `
| Set-AzureRmSqlDatabaseTransparentDataEncryption -State Enabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment