Skip to content

Instantly share code, notes, and snippets.

@dazfuller
Last active January 12, 2017 10:51
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/32daeaad1af88098b658ee816b0688c8 to your computer and use it in GitHub Desktop.
Save dazfuller/32daeaad1af88098b658ee816b0688c8 to your computer and use it in GitHub Desktop.
<#
.DESCRIPTION
A runbook which finds storage accounts without encryption services enabled and
enables them
.NOTES
AUTHOR: @dazfuller
LASTEDIT: Jan 11, 2017
#>
workflow EnableStorageAccountEncryption
{
$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 resource groups
$resourceGroups = Get-AzureRmResourceGroup
ForEach -Parallel ($resourceGroup in $resourceGroups)
{
# Get storage accounts for the resource group
$storageAccounts = Get-AzureRmStorageAccount -ResourceGroupName $resourceGroup.ResourceGroupName
ForEach ($storageAccount in $storageAccounts)
{
# If the storage account does not have encryption services enabled then enable them
if ($storageAccount.Encryption -eq $null)
{
Write-Output "Enabling encryption services for $($storageAccount.Id)"
Set-AzureRmStorageAccount -Name $storageAccount.StorageAccountName -ResourceGroupName $resourceGroup.ResourceGroupName -EnableEncryptionService Blob
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment