Closed patiljayesh040 closed 4 years ago
@patiljayesh040 - Thanks for brining this to our attention. We will investigate it further and update you shortly.
@patiljayesh040 - This will be done using cmdlets in the Az.RecoveryServices module https://docs.microsoft.com/powershell/module/az.recoveryservices..
At this moment, Since there is no doc update required, We will now proceed to close this thread. If there are further questions regarding this matter, please tag me in your reply. We will gladly continue the discussion and we will reopen the issue.
Hope this might help:
`# Ensure you have installed and configured the Azure PowerShell module
Connect-AzAccount
Set-AzContext -SubscriptionId "
$resourceGroupName = "
$vault = Get-AzRecoveryServicesVault -ResourceGroupName $resourceGroupName -Name $vaultName
if ($vault -eq $null) { Write-Error "Vault not found. Please check the vault name and resource group." exit }
Set-AzRecoveryServicesVaultContext -Vault $vault Set-AzRecoveryServicesAsrVaultContext -Vault $vault
try { $fabrics = Get-AzRecoveryServicesAsrFabric } catch { Write-Error "Error getting fabrics: $_" exit }
if ($fabrics.Count -eq 0) { Write-Error "No fabrics found." exit }
$itemsToUpdate = @()
foreach ($fabric in $fabrics) { try {
$protectionContainers = Get-AzRecoveryServicesAsrProtectionContainer -Fabric $fabric
} catch {
Write-Error "Error getting Protection Containers for fabric $($fabric.FriendlyName): $_"
continue
}
# Iterate through each Protection Container to get the replicated items
foreach ($container in $protectionContainers) {
try {
# Get the replicated items for the specified container
$replicatedItems = Get-AzRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $container
} catch {
Write-Error "Error getting replicated items for container $($container.Name): $_"
continue
}
# Check the Site Recovery Replication Agent status for each replicated item
foreach ($item in $replicatedItems) {
# Get provider-specific details
$providerDetails = $item.ProviderSpecificDetails
$vmName = $item.ReplicationProtectedItemFriendlyName
# Extract the VM name from FabricObjectId if ReplicationProtectedItemFriendlyName is empty
if ([string]::IsNullOrWhiteSpace($vmName)) {
$vmName = ($providerDetails.FabricObjectId -split '/')[-1]
}
# Check if the replication agent update is required
if ($providerDetails.IsReplicationAgentUpdateRequired -eq $true) {
$itemsToUpdate += [PSCustomObject]@{
VMName = $vmName
AgentVersion = $providerDetails.AgentVersion
IsReplicationAgentUpdateRequired = $providerDetails.IsReplicationAgentUpdateRequired
PrimaryFabricFriendlyName = $item.PrimaryFabricFriendlyName
RecoveryFabricFriendlyName = $item.RecoveryFabricFriendlyName
}
}
}
}
}
$outputFile = ".\output.csv"
$itemsToUpdate | Export-Csv -Path $outputFile -NoTypeInformation
Write-Output "Export completed. File saved to: $outputFile" `
Hello All,
I just need help with PowerShell script to get ASR replication status for all servers in Azure Subscriptions with Azure-to-Azure disaster recovery setup.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.