To Retrieve a List of Source and Target Datastores in vSphere Replication
search cancel

To Retrieve a List of Source and Target Datastores in vSphere Replication

book

Article ID: 403596

calendar_today

Updated On:

Products

VMware vSphere ESXi

Issue/Introduction

In the vSphere Replication UI, the target datastore can be seen by expanding each VM entry. However, in large environments with many replication servers and numerous virtual machines, manually retrieving source and target datastore information becomes inefficient and error-prone.

Environment

Some enterprises require a complete list of source and target datastores for purposes such as audit, capacity planning, or compliance.

Resolution

The following PowerCLI script retrieves the source and target datastores for each replication pair.

=================================
$VR1 = "IP or FQDN of VR server in source site"
$VR1_user = "[email protected]"
$VR1_password = "Password of above user"

$VC2 = "IP or FQDN of vCenter in target site"
$VC2_user = "[email protected]"
$VC2_password = "Password of above user"

$vr = Connect-VrServer -Server $VR1 -User $VR1_user -Password $VR1_password -RemoteServer $VC2 -RemoteUser $VC2_user -RemotePassword $VC2_password
$Pairing = (Invoke-VrGetVrPairings).List

foreach ( $PairingId in $Pairing.PairingId ) {
    $rep = Invoke-VrGetAllReplications -PairingId $PairingId -FilterProperty "Name" -Server $vr

    foreach ( $vm in $rep.List ) {
        $replication_name = $vm.Name
        $replication_id = $vm.Id
        $SourceSite = $vm.SourceSiteName
        $TargetSite = $vm.TargetSiteName

        $ReplicatedVmDisk = Invoke-VrGetReplicatedVmDisks -PairingId $PairingId -ReplicationId $replication_id

        $ReplicatedVmDisk.List | Select-Object  @{Name='SourceSite'; Expression = {$SourceSite}}, @{Name='TargetSite'; Expression = {$TargetSite}}, @{Name='SourceDatastore'; Expression = {$_.VmDisk.SourcePath.DatastoreName }}, @{Name='SourcePath'; Expression = {$_.VmDisk.SourcePath.Path }}, @{Name='SourceFilename'; Expression = {$_.VmDisk.SourcePath.FileName }}, @{Name='TargetDatastore'; Expression = {$_.DestinationPath.DatastoreName }},  @{Name='TargetPath'; Expression = {$_.DestinationPath.Path }}, @{Name='TargetFilename'; Expression = {$_.DestinationPath.FileName }} |ft -autosize
    }
}

Disconnect-VrServer -Server $VR1
================================

Please note the following before running the script:

  • $VR1 refers to the vSphere Replication server at the source site
  • $VC2 refers to the vCenter Server at the target site.
  • If an SSO domain other than vsphere.local is used, please update the username accordingly.
  • Verify how the remote vCenter (i.e., the target site vCenter) is registered in $VR1 — whether as an IP address or a fully qualified domain name (FQDN). Based on this configuration, input the corresponding value (IP or FQDN) into the script for $VC2.

⚠️ If the target site vCenter is registered using an FQDN in $VR1, but you enter an IP address for $VC2, the script will fail to connect.