admin管理员组

文章数量:1309988

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'
  }
}
Share Improve this question edited Feb 5 at 15:14 qkfang 1,7871 silver badge20 bronze badges asked Feb 3 at 7:15 satish Bsatish B 412 bronze badges 5
  • Any blocker you faced soo far @satishB – Vinay B Commented Feb 3 at 10:50
  • @vinay B: i tried to refer multiple blogs . But No Luck – satish B Commented Feb 4 at 5:29
  • Have you tried this template github/Azure/azure-quickstart-templates/blob/… . You will deploy serveral vault related sub-resources. – wenbo Commented Feb 5 at 2:18
  • @wenbo: thanks for sharing the link.But iam looking powershell automation script to enable site recovery for multiple vm's. – satish B Commented Feb 6 at 6:38
  • @satish B, Above link provided it is related to single vm site recovery enable. The mechanism is the same, multiple vm's are just adding Loop in bicep. The main point here is to enable site recovery to vm (it's not easy, because of many of sub-resources and conceptions), not to multiple vm. I've searched and haven't found a bicep file that includes both enable site recovery and multiple vms. – wenbo Commented Feb 6 at 7:19
Add a comment  | 

1 Answer 1

Reset to default 0

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

本文标签: Need to enable VM Replication using azure bicep with Powershell scriptStack Overflow