I found an article here, https://00shep.blogspot.com/2019/07/azure-script-audit-recovery-plans-for.html and borrowed some of the code.
`$RecoveryPlan = Get-AzRecoveryServicesAsrRecoveryPlan | where {$_.name -eq $rpName
#get all replicated items
$ReplicationProtectedItem = Get-AzRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $PrimaryProtContainer
#Array to house the protected items it plan
$ObjectArray = New-Object System.Collections.Generic.List[System.Object]
foreach($group in $plandetails.Groups) {
foreach ($groupprotecteditem in $group.ReplicationProtectedItems) {
$VMmatch = Get-AzRecoveryServicesAsrProtectableItem -ProtectionContainer $asrcontainer | where { $.ProtectionStatus -eq 'Protected' -and $.ReplicationProtectedItemId -eq $groupprotecteditem.id} | Select -expand FriendlyName
$tempArray = New-Object System.Object
$tempArray | Add-Member -MemberType NoteProperty -Name "VMName" -Value $VMmatch
$tempArray | Add-Member -MemberType NoteProperty -Name "RecoveryPlan" -Value $recoveryplan
$tempArray | Add-Member -MemberType NoteProperty -Name "Group" -Value $group.name
$tempArray | Add-Member -MemberType NoteProperty -Name "ProtectedItem" -Value $groupprotecteditem
$tempArray | Add-Member -MemberType NoteProperty -Name "ID" -Value $groupprotecteditem.id
$ObjectArray.add($tempArray)
}
}
#$ObjectArray gives IDs - get the IDs and compare to Names in $replicateditems.
$planVMs= @()
foreach ($obObject in $ObjectArray.id) {
$row = "" | select "VMNAME","ID"
$obid = ($obObject -split "/")[14]
$vm = ($ReplicationProtectedItem | where {$_.name -eq $obid}).FriendlyName
$row."VMNAME" = $vm
$row."ID" = $obid
$planVMs += $row
}
and the result of $planVMs is
$planVMs
VMNAME ID
ASRTEST01 myvc01_503d77c6-c646-5faa-c4da-92f2cd3d2731
ASRTEST02 myvc01_503d9413-2e92-5ea6-3032-616bacd8f8ae`