Last active
January 13, 2017 22:18
-
-
Save dazfuller/be132cc19728d9de428bdf26b106928d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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