Skip to content

Instantly share code, notes, and snippets.

@artisticcheese
Last active September 6, 2018 01:22
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 artisticcheese/33d5061f4cd18ab24eec7ca6d9d77299 to your computer and use it in GitHub Desktop.
Save artisticcheese/33d5061f4cd18ab24eec7ca6d9d77299 to your computer and use it in GitHub Desktop.
param (
[Object]$RecoveryPlanContext # = ('{"RecoveryPlanName":"RecoverSQLservers","FailoverType":"Test","FailoverDirection":"PrimaryToSecondary","GroupId":"Group1","VmMap":{"79b0a60c-a71f-4c0f-a6ec-e62287200466":{"SubscriptionId":"4c120485-e0cd-4787-8dc9-d3608a41fde3","ResourceGroupName":"WestUS-RG","CloudServiceName":null,"RoleName":"sql1-test","RecoveryPointId":"e734ce77-5753-476c-974b-23d50dd2c177","RecoveryPointTime":"\/Date(1535766878775)\/"}}}' | convertfrom-json)
)
Write-output $RecoveryPlanContext
$RecoveryPlanContext = $RecoveryPlanContext | convertfrom-json -ErrorAction Ignore
$VMinfo = $RecoveryPlanContext.VmMap | Get-Member | Where-Object MemberType -EQ NoteProperty | select -ExpandProperty Name
$vmMap = $RecoveryPlanContext.VmMap
Write-Output $VMInfo
"Logging in to Azure..."
$Conn = Get-AutomationConnection -Name AzureRunAsConnection
Add-AzureRMAccount -ServicePrincipal -Tenant $Conn.TenantID -ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint
"Selecting Azure subscription..."
Select-AzureRmSubscription -SubscriptionId $Conn.SubscriptionID -TenantId $Conn.tenantid
foreach($VMID in $VMinfo)
{
$VM = $vmMap.$VMID
if( !(($VM -eq $Null) -Or ($VM.ResourceGroupName -eq $Null) -Or ($VM.RoleName -eq $Null))) {
$keyVaultName = Get-AutomationVariable -Name 'FailoverKeyVaultName'
Write-Output "Calling reencrypt OS disk with following parameters vmName:$($Vm.RoleName), rgName:$($VM.ResourceGroupName), keyVaultName:$($keyVaultName)"
.\EncryptVMOSDisk.ps1 -VMName $($VM.RoleName) -rgName $($VM.ResourceGroupName) -keyVaultName $keyVaultName
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment