PowerShell script exchange
Post Reply
snzhang2
Influencer
Posts: 22
Liked: 1 time
Joined: Oct 12, 2016 3:17 pm
Full Name: Nan Zhang
Contact:

Determine if replication job has VM replica mapping

Post by snzhang2 »

I am looking for a way to find if a replication job has VM replica mapping set. I am using VBR 9.0.

I am aware of the option $replicajob.ViReplicaTargetOptions.UseVmMapping. But this just checks if the VM seeding is enabled but it doesn't tell if a replica VM is mapped.
Vitaliy S.
VP, Product Management
Posts: 27112
Liked: 2719 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: Determine if replication job has VM replica mapping

Post by Vitaliy S. »

Can you please tell us a bit more about your use case? This would help us to give a better answer to your question.
snzhang2
Influencer
Posts: 22
Liked: 1 time
Joined: Oct 12, 2016 3:17 pm
Full Name: Nan Zhang
Contact:

Re: Determine if replication job has VM replica mapping

Post by snzhang2 »

At the moment we have three hundreds or so replication jobs created for a datacentere migration move. We want to use VM mapping once there is a replica is in place. But what I found is that even if the 'UseVMMapping' option is enabled it doesn't always mean that a source VM is mapped to its replica (Under replication job property, Seeding -> Replica Mapping), so what I wanted to do is identify those replication jobs that do not have VM mapping (ie "Replica VM" under the Seeding showing "No Mapping").

Hope this is clear.
Vitaliy S.
VP, Product Management
Posts: 27112
Liked: 2719 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: Determine if replication job has VM replica mapping

Post by Vitaliy S. »

Ok, thanks! Cannot comment on how to achieve that via PS (not an expert), but you can try this report to see all the settings for replication jobs > Job Configuration Dump
snzhang2
Influencer
Posts: 22
Liked: 1 time
Joined: Oct 12, 2016 3:17 pm
Full Name: Nan Zhang
Contact:

Re: Determine if replication job has VM replica mapping

Post by snzhang2 »

Thanks for the suggestion. The report does have the VM mapping information for these replication jobs but unfortunately it spans over 1000+ pages so it isn't very practical.

Without a way to extract this information via PS, the best option is to try to remap the VM regardless where it is needed or not.
tsightler
VP, Product Management
Posts: 6011
Liked: 2843 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Determine if replication job has VM replica mapping

Post by tsightler »

While I could not find any obvious way to do this with the native cmdlets/objects, here's some details for some internal functions that might help you.
This function will return an array with all mapped object for a given job ID:

Code: Select all

[Veeam.Backup.Core.CReplicaMapping]::Get(jobId)
This function will return the individual mapped object for any given combination of job and object ID:

Code: Select all

[Veeam.Backup.Core.CReplicaMapping]::Find(jobId, objectId)
As long as the VMs are added to the job individually rather than via some container object like a folder or datastore, then something like this could do what you want (just an example but easy to extend):

Code: Select all

$jobName = "<Job_Name>"

$job = Get-VBRJob -Name $jobName
$jobObjs = Get-VBRJobObject -Job $job

foreach ($jobObj in $jobObjs) {
    $vmmap = $null
    $vmmap = [Veeam.Backup.Core.CReplicaMapping]::Find($job.id, $jobObj.ObjectId)
    if ($vmmap) {
        write-host -ForegroundColor Green "VM $($jobObj.Name) is mapped to VM $($vmmap.MappedObj)"
    } else {
        write-host -ForegroundColor Yellow "WARNING - VM $($jobObj.Name) is NOT mapped!"
    }
}
snzhang2
Influencer
Posts: 22
Liked: 1 time
Joined: Oct 12, 2016 3:17 pm
Full Name: Nan Zhang
Contact:

Re: Determine if replication job has VM replica mapping

Post by snzhang2 »

Thank you!

This code does exactly what I am looking for. I just had to parameterized it so I can use it with a foreach statement, like so.

Code: Select all

get-vbrjob | ? { $_.jobtype -eq 'replica' } | % { .\get-MappedVM.ps1 -jobname $_.name }
The full get-MappedVM.ps1 script is as below:

Code: Select all

param (
[Parameter(Mandatory=$true)]
$jobName
)

$job = Get-VBRJob -Name $jobName
$jobObjs = Get-VBRJobObject -Job $job

foreach ($jobObj in $jobObjs) {
    $vmmap = $null
    $vmmap = [Veeam.Backup.Core.CReplicaMapping]::Find($job.id, $jobObj.ObjectId)
    if ($vmmap) {
$sourceVMString = "[{0,24}]" -f $jobObj.name
        write-host -ForegroundColor Green "VM $sourceVMstring is mapped to VM $($vmmap.MappedObj)"
    } else {
        write-host -ForegroundColor Yellow "WARNING - VM $($jobObj.Name) is NOT mapped!"
    }
}
tamosi
Lurker
Posts: 1
Liked: never
Joined: Feb 02, 2024 4:24 pm
Full Name: tamosi
Contact:

Re: Determine if replication job has VM replica mapping

Post by tamosi »

Hello,

Sorry to reply on an old thread, does anyone know how to do it when I have a folder or a host in the replica job ?

thanks in advance for your help.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 13 guests