Need to enable VM Replication using azure bicep with PowerShell script .I have created the configuration like rsv.bicep. while enabling VM replication using PowerShell script ,Variables & parameters to be taken from rsv.bicep
param rsv string = 'testing-rsv'
param location string = resourceGroup().location
param VMlist array = [VM1,VM2]
resource recoveryServiceVault 'Microsoft.RecoveryServices/vaults@2021-01-01' = {
name: rsv
location: location
sku: {
name: 'RS0'
tier: 'Standard'
}
}
Need to enable VM Replication using azure bicep with PowerShell script .I have created the configuration like rsv.bicep. while enabling VM replication using PowerShell script ,Variables & parameters to be taken from rsv.bicep
param rsv string = 'testing-rsv'
param location string = resourceGroup().location
param VMlist array = [VM1,VM2]
resource recoveryServiceVault 'Microsoft.RecoveryServices/vaults@2021-01-01' = {
name: rsv
location: location
sku: {
name: 'RS0'
tier: 'Standard'
}
}
Need to enable VM Replication using azure bicep with Powershell script
You can use a deployment script in Bicep to run a PowerShell script that enables VM replication for multiple VMs.
Note: Make sure to place the powershell script in same bicep file directory
Here is the PoPowerShellcript
$VMlist = @("VenkatVM", "VenkatVM1")
$vaultID = "/subscriptions/8332bcn6575755f09a9/resourceGroups/Venkat-VM/providers/Microsoft.RecoveryServices/vaults/Venkat-RSV"
$location= "eastus"
$resourceGroupName="Venkat-VM"
#Get the vault object
$vault = Get-AzRecoveryServicesVault -Name "Venkat-RSV"
foreach ($vmName in $VMlist) {
# Set the recovery services vault context
Set-AzRecoveryServicesVaultContext -Vault $vault
# Get the backup protection policy
$policy = Get-AzRecoveryServicesBackupProtectionPolicy -Name "DefaultPolicy"
# Enable backup protection for each VM (passing the vmName string)
Enable-AzRecoveryServicesBackupProtection -ResourceGroupName $resourceGroupName -Name $vmName -Policy $policy
Write-Output "Replication enabled for $vmName"
}
Here is the Bicep code to use the PowerShell script to enable VM replication.
vm.bicep
var scriptContentEndpoint = loadTextContent('./vm.ps1')
resource scriptEndpoint 'Microsoft.Resources/deploymentScripts@2020-10-01' = {
name: 'DisableendpointScript'
location: resourceGroup().location
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'/subscriptions/8332bf56-aa7c-4daa-a507-d7e60e5f09a9/resourceGroups/Venkat-VM/providers/Microsoft.ManagedIdentity/userAssignedIdentities/RSV-UAM': {}
}
}
kind: 'AzurePowerShell'
properties: {
azPowerShellVersion: '10.1'
retentionInterval: 'PT1H'
scriptContent: scriptContentEndpoint
}
}
New-AzResourceGroupDeployment -ResourceGroupName "Venkat-VM" -TemplateFile "vm.bicep"
Response:
Reference : azure - Powershell module can't find subscription when a bicep kicks it off - Stack Overflow
bicep
file that includes both enable site recovery and multiple vms. – wenbo - Finding Job Commented Feb 6 at 7:19