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
|
1 Answer
Reset to default 0Need 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
版权声明:本文标题:Need to enable VM Replication using azure bicep with Powershell script - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741833934a2400101.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
bicep
file that includes both enable site recovery and multiple vms. – wenbo Commented Feb 6 at 7:19