Azure Failover Settings details via powershell script

Ravi Kiran Moole 80 Reputation points
2025-06-13T03:50:11.9266667+00:00

How to find the DR failover IP settings from the below path:

VM -> BAckup + Disaster Recovery -> under general -> Network ->under primary IP configuration, I need to get all details of below:

"Properties", "Source Settings", "Test failover settings", "failover settings"

Need above details via powershell script, is that possible?

please find the attached screenshot for reference.

We have more than 100 VM's to find those details and validate, so i need your help in getting the script to find those detailsUser's image

Azure Site Recovery
Azure Site Recovery
An Azure native disaster recovery service. Previously known as Microsoft Azure Hyper-V Recovery Manager.
824 questions
{count} votes

Accepted answer
  1. Rahul Jorrigala 660 Reputation points Microsoft External Staff Moderator
    2025-06-30T09:09:00.6666667+00:00

    Hi Ravi,

    As discussed, Please use below Resource graph query to fetch the required details.

    RecoveryServicesResources
    | where type =~ 'microsoft.recoveryservices/vaults/replicationFabrics/replicationProtectionContainers/replicationProtectedItems'
    | extend props = properties
    | project
        name,
        vaultName = tostring(split(id, "/")[8]),
        resourceGroup = tostring(split(id, "/")[4]),
        location,
        friendlyName = props.friendlyName,
        protectionState = props.protectionState,
        recoveryStaticIP = tostring(props.providerSpecificDetails.vmNics[0].ipConfigs[0].recoveryStaticIPAddress),
        originalStaticIP = tostring(props.providerSpecificDetails.vmNics[0].ipConfigs[0].staticIPAddress),
        testFailoverStaticIP = tostring(props.providerSpecificDetails.vmNics[0].ipConfigs[0].tfoStaticIPAddress),
        recoverySubnet = tostring(props.providerSpecificDetails.vmNics[0].ipConfigs[0].recoverySubnetName),
        originalSubnet = tostring(props.providerSpecificDetails.vmNics[0].ipConfigs[0].subnetName),
        testFailoverSubnet = tostring(props.providerSpecificDetails.vmNics[0].ipConfigs[0].tfoSubnetName)
    
    
    

    Please let me know if you face any challenge here, I can help you to resolve this issue further

    Provide your valuable Comments.

    Please do not forget to "Accept the answer” and “upvote it” wherever the information provided helps you, this can be beneficial to other community members.it would be greatly appreciated and helpful to others.

    1 person found this answer helpful.

3 additional answers

Sort by: Most helpful
  1. Vinod Pittala 4,095 Reputation points Microsoft External Staff Moderator
    2025-06-13T07:29:45.23+00:00

    Hello Ravi Kiran Moole,

    Based on your description, you're aiming to extract Disaster Recovery (DR) failover network settings for multiple Azure VMs protected by Azure Site Recovery (ASR). specifically details like:

    • Properties
    • Source Settings
    • Test Failover Settings
    • Failover Settings

    Yes, this can be achievable using PowerShell. Before running the script, please ensure the following prerequisites are met :

    • The latest Az PowerShell modules are installed.
    • You are authenticated using Connect-AzAccount.
    • You have the necessary permissions on the Recovery Services Vault and the associated VMs.

    Below is a PowerShell script that retrieves the required DR network configuration details across all Recovery Services Vaults in your subscription:

    # Connect to Azure and set your subscription
    Connect-AzAccount
    $subscriptionId = "<your-subscription-id>"  # Replace with your subscription ID
    Select-AzSubscription -SubscriptionId $subscriptionId
    
    # Get all Recovery Services Vaults (adjust if you know the vault name)
    $vaults = Get-AzRecoveryServicesVault
    
    # Store results
    $results = @()
    
    foreach ($vault in $vaults) {
        Set-AzRecoveryServicesVaultContext -Vault $vault
    
        # Get all replication protected items in the vault
        $protectedItems = Get-AzRecoveryServicesAsrReplicationProtectedItem
    
        foreach ($item in $protectedItems) {
            $vmName = $item.FriendlyName
            $networkConfig = $item.NetworkConfiguration
    
            # Build result object
            $results += [PSCustomObject]@{
                VMName                 = $vmName
                VaultName              = $vault.Name
                SourceSubnet           = $networkConfig.SourceNetworkSubnet
                TestFailoverSubnet     = $networkConfig.TestFailoverNetworkSettings?.SubnetName
                TestFailoverIP         = $networkConfig.TestFailoverNetworkSettings?.StaticIPAddress
                FailoverSubnet         = $networkConfig.FailoverNetworkSettings?.SubnetName
                FailoverIP             = $networkConfig.FailoverNetworkSettings?.StaticIPAddress
                IPAllocationMethod     = $networkConfig.FailoverNetworkSettings?.IPAddressType
            }
        }
    }
    
    # Optional: export to CSV
    $results | Export-Csv -Path "ASR_DR_Failover_Settings.csv" -NoTypeInformation
    
    # Show results
    $results
    
    

    Please let me know if you ave any further queries or issues on the same.

    If the provided solution works for your query, please do not forget to Upvote it. this can be beneficial to other community members.it would be greatly appreciated and helpful to others.

    Thanks


  2. Vinod Pittala 4,095 Reputation points Microsoft External Staff Moderator
    2025-06-17T09:18:24.16+00:00

    Hello Ravi Kiran Moole,

    Apologies for the delay in getting back to you.

    Regarding your query—if you have a list of virtual machine (VM) names stored in a text or CSV file, you can use the script below to retrieve details for those specific VMs. This approach allows you to automate the process and efficiently gather the required information.

    Please let me know if you need help customizing the script or if you’d like assistance with a specific file format.

    # CSV with a column named "VMName"
    $targetVMs = Import-Csv -Path "TargetVMList.csv" | Select-Object -ExpandProperty VMName
    
     
    foreach ($vault in $vaults) {
        Set-AzRecoveryServicesVaultContext -Vault $vault
     
        try {
            $protectedItems = Get-AzRecoveryServicesAsrReplicationProtectedItem
        } catch {
            Write-Warning "Failed to retrieve protected items for vault $($vault.Name): $_"
            continue
        }
     
        foreach ($item in $protectedItems) {
            $vmName = $item.FriendlyName
     
            if ($targetVMs -contains $vmName) {
                $networkConfig = $item.NetworkConfiguration
     
                if (-not $networkConfig) {
                    Write-Warning "No network config for VM $vmName in vault $($vault.Name)"
                    continue
                }
     
                $results += [PSCustomObject]@{
                    VMName                 = $vmName
                    VaultName              = $vault.Name
                    SourceSubnet           = $networkConfig.SourceNetworkSubnet
                    TestFailoverSubnet     = $networkConfig.TestFailoverNetworkSettings?.SubnetName
                    TestFailoverIP         = $networkConfig.TestFailoverNetworkSettings?.StaticIPAddress
                    FailoverSubnet         = $networkConfig.FailoverNetworkSettings?.SubnetName
                    FailoverIP             = $networkConfig.FailoverNetworkSettings?.StaticIPAddress
                    IPAllocationMethod     = $networkConfig.FailoverNetworkSettings?.IPAddressType
                }
            }
        }
    }
    
    
    
    

    Please do not forget to “upvote it” wherever the information provided helps you, this can be beneficial to other community members.it would be greatly appreciated and helpful to others.

    Thanks

    0 comments No comments

  3. Ravi Kiran Moole 80 Reputation points
    2025-06-24T06:01:19.5533333+00:00

    Hello Vinod

    Please see my earlier post which i have giving the script along with the error message which i am getting, please share the new script so i can test and confirm back with all needs required.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.