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.
Some enterprises require a complete list of source and target datastores for purposes such as audit, capacity planning, or compliance.
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:
⚠️ 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.