Skip to content

Instantly share code, notes, and snippets.

@DataSic
Last active December 5, 2017 16:47
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 DataSic/5fa42bb829180418fe124f62f641de08 to your computer and use it in GitHub Desktop.
Save DataSic/5fa42bb829180418fe124f62f641de08 to your computer and use it in GitHub Desktop.
try
{
# Built-in account
$servicePrincipalConnection = Get-AutomationConnection -Name "AzureRunAsConnection"
# Init variables (Automation Account variables)
$ResourceGroup = Get-AutomationVariable -Name 'ResourceGroup'
$SqlServerName = Get-AutomationVariable -Name 'SqlServerName'
$DatabaseName = Get-AutomationVariable -Name 'DatabaseName'
# Log into Azure with AzureRunAsConnection
$null = Add-AzureRmAccount -ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
# Get GeoBackupPolicy State (Enabled?)
$state = (Get-AzureRmSqlDatabaseGeoBackupPolicy -ResourceGroupName $ResourceGroup `
-ServerName $SqlServerName `
-DatabaseName $DatabaseName).State
$state
# Get LastAvailableBackupDate
$lastAvailableBackupDate = (Get-AzureRmSqlDatabaseGeoBackup -ResourceGroupName $ResourceGroup `
-ServerName $SqlServerName `
-DatabaseName $DatabaseName).LastAvailableBackupDate
$lastAvailableBackupDate
}
catch {
throw $_.Exception
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment