Determine if replication job has VM replica mapping

PowerShell script exchange

Determine if replication job has VM replica mapping

Veeam Logoby snzhang2 » Tue Dec 20, 2016 5:50 pm

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.
snzhang2
Influencer
 
Posts: 22
Liked: 1 time
Joined: Wed Oct 12, 2016 3:17 pm
Full Name: Nan Zhang

Re: Determine if replication job has VM replica mapping

Veeam Logoby Vitaliy S. » Wed Dec 21, 2016 1:57 pm

Can you please tell us a bit more about your use case? This would help us to give a better answer to your question.
Vitaliy S.
Veeam Software
 
Posts: 19961
Liked: 1145 times
Joined: Mon Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov

Re: Determine if replication job has VM replica mapping

Veeam Logoby snzhang2 » Thu Dec 22, 2016 4:47 pm

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.
snzhang2
Influencer
 
Posts: 22
Liked: 1 time
Joined: Wed Oct 12, 2016 3:17 pm
Full Name: Nan Zhang

Re: Determine if replication job has VM replica mapping

Veeam Logoby Vitaliy S. » Fri Dec 23, 2016 12:44 pm

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
Vitaliy S.
Veeam Software
 
Posts: 19961
Liked: 1145 times
Joined: Mon Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov

Re: Determine if replication job has VM replica mapping

Veeam Logoby snzhang2 » Fri Dec 23, 2016 10:54 pm

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.
snzhang2
Influencer
 
Posts: 22
Liked: 1 time
Joined: Wed Oct 12, 2016 3:17 pm
Full Name: Nan Zhang

Re: Determine if replication job has VM replica mapping

Veeam Logoby tsightler » Sat Dec 24, 2016 2:22 am

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!"
    }
}
tsightler
Veeam Software
 
Posts: 4873
Liked: 1821 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: Determine if replication job has VM replica mapping

Veeam Logoby snzhang2 » Thu Dec 29, 2016 5:01 pm

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!"
    }
}
snzhang2
Influencer
 
Posts: 22
Liked: 1 time
Joined: Wed Oct 12, 2016 3:17 pm
Full Name: Nan Zhang


Return to PowerShell



Who is online

Users browsing this forum: BCHAD and 1 guest