PowerShell script exchange
Post Reply
digitalexpl0it
Influencer
Posts: 18
Liked: 4 times
Joined: Jul 21, 2016 1:31 am
Full Name: Derrick Rose
Contact:

List all Replica VMs

Post by digitalexpl0it »

I am trying to write a powershell script that will remote into the main Veeam Backup & Replication server and pull all the Replica VMs. So far the script that I have written seems to pull all the replica VMs but its also pulling VMs not shown in Veeam, when I look at the console under Replica. These are old VMs that have been removed long ago but for some reason is showing in the results. Any help is appreciated.

Code: Select all

function Veeam_Replica_VMs($vbrServer) {
	$s = New-PSSession -ComputerName $vbrServer
	Invoke-Command -Session $s -ScriptBlock { Add-PSSnapin VeeamPSSnapin }
	Invoke-Command -Session $s -ScriptBlock { 
		$VMS = Get-VBRBackupSession | Where-Object {$_.JobType -eq "Replica" -and $_.EndTime}|foreach{$_.gettasksessions() | Where-Object {$_.Status -ne "Failed"}} |foreach{$_.Name} | Sort-Object | Get-Unique
		return $VMS
	}
	
	Exit-PSSession
	Remove-PSSession -ID $s.ID
}

Veeam_Replica_VMs -vbrServer "VeeamServer_HERE"

PetrM
Veeam Software
Posts: 3229
Liked: 519 times
Joined: Aug 28, 2013 8:23 am
Full Name: Petr Makarov
Location: Prague, Czech Republic
Contact:

Re: List all Replica VMs

Post by PetrM »

Hi Derrick!

Looks like the script is getting task sessions of replication jobs which still exist in Veeam configuration database instead of querying replica objects.
Please try to use this cmdlet and let us know the result.

Thanks!
digitalexpl0it
Influencer
Posts: 18
Liked: 4 times
Joined: Jul 21, 2016 1:31 am
Full Name: Derrick Rose
Contact:

Re: List all Replica VMs

Post by digitalexpl0it »

Thanks for the reply, I was playing around with Get-VBRReplica, but wasn't sure how to pull the list of VMs in the job. I only get the list of replica jobs. If I choose one of the jobs its just list the job details (Job Name, Type, Creation Time, VM Count)

Example: Get-VBRReplica -Name "DC Replica"
digitalexpl0it
Influencer
Posts: 18
Liked: 4 times
Joined: Jul 21, 2016 1:31 am
Full Name: Derrick Rose
Contact:

Re: List all Replica VMs

Post by digitalexpl0it »

The end goal is to grab a list of VMs that have been replicated then cross reference that list with VMWare and pull the tags from the VM from VMWare. I use tagging in VMWare to assign VMs to backup and replica jobs. I use two products for replication, Zerto and Veeam. I just want to verify both are not replicating the same VM.
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: List all Replica VMs

Post by veremin » 1 person likes this post

I just want to verify both are not replicating the same VM
But wouldn't it be easier to create two tags (Veeam, Zerto), assign them to corresponding VMs and use these tags as source for Veeam and Zerto jobs accordingly? Thanks!
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: List all Replica VMs

Post by oleg.feoktistov »

digitalexpl0it wrote: Oct 15, 2019 12:09 am I was playing around with Get-VBRReplica, but wasn't sure how to pull the list of VMs in the job. I only get the list of replica jobs. If I choose one of the jobs its just list the job details (Job Name, Type, Creation Time, VM Count)
Please try to pass job names from Get-VBRReplica stdout to Get-VBRJobObject cmdlet as -Job parameter inside a ForEach statement:

Code: Select all

$replicas = Get-VBRReplica | Select Name
$replicas = $replicas.Name
ForEach ($replica in $replicas) { Get-VBRJobObject -Job $replica}
You can read more on Get-VBRJobObject cmdlet here
digitalexpl0it
Influencer
Posts: 18
Liked: 4 times
Joined: Jul 21, 2016 1:31 am
Full Name: Derrick Rose
Contact:

Re: List all Replica VMs

Post by digitalexpl0it »

veremin wrote: Oct 15, 2019 10:16 am But wouldn't it be easier to create two tags (Veeam, Zerto), assign them to corresponding VMs and use these tags as source for Veeam and Zerto jobs accordingly? Thanks!
This is what I am doing already for the past 4 years. Zerto doesn't support VMWare tagging.
digitalexpl0it
Influencer
Posts: 18
Liked: 4 times
Joined: Jul 21, 2016 1:31 am
Full Name: Derrick Rose
Contact:

Re: List all Replica VMs

Post by digitalexpl0it »

oleg.feoktistov wrote: Oct 15, 2019 1:42 pm Please try to pass job names from Get-VBRReplica stdout to Get-VBRJobObject cmdlet as -Job parameter inside a ForEach statement:

Code: Select all

$replicas = Get-VBRReplica | Select Name
$replicas = $replicas.Name
ForEach ($replica in $replicas) { Get-VBRJobObject -Job $replica}
You can read more on Get-VBRJobObject cmdlet here
Got it thanks, I will try this.
digitalexpl0it
Influencer
Posts: 18
Liked: 4 times
Joined: Jul 21, 2016 1:31 am
Full Name: Derrick Rose
Contact:

Re: List all Replica VMs

Post by digitalexpl0it »

oleg.feoktistov wrote: Oct 15, 2019 1:42 pm Please try to pass job names from Get-VBRReplica stdout to Get-VBRJobObject cmdlet as -Job parameter inside a ForEach statement:

Code: Select all

$replicas = Get-VBRReplica | Select Name
$replicas = $replicas.Name
ForEach ($replica in $replicas) { Get-VBRJobObject -Job $replica}
You can read more on Get-VBRJobObject cmdlet here
I am now able to pull whats in the Replica Jobs, but since I used tags for all my jobs, only the tags are pulled. I think my original way will work, I just need to verify it exists in VMWare before doing any checks on the VMs
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: List all Replica VMs

Post by veremin » 1 person likes this post

I am now able to pull whats in the Replica Jobs, but since I used tags for all my jobs, only the tags are pulled.
Then,

- Check what VMs are located under those tags, using Find-VBRViEntity cmdlet
- Compare two resulting lists and check whether there are any VMs present in both lists

Thanks!
digitalexpl0it
Influencer
Posts: 18
Liked: 4 times
Joined: Jul 21, 2016 1:31 am
Full Name: Derrick Rose
Contact:

Re: List all Replica VMs

Post by digitalexpl0it »

Thanks, I will try that
quentinl
Lurker
Posts: 1
Liked: never
Joined: Nov 03, 2023 2:15 pm
Contact:

[MERGED] How can i get the list of VM in "Replica"

Post by quentinl »

Hello,

Do you know if it is possible to list the name of all VM in "Replica" and not the Job Name ? (I already used the cmd Get-VBRReplica and it only gave me JobName)
Mildur
Product Manager
Posts: 8549
Liked: 2223 times
Joined: May 13, 2017 4:51 pm
Full Name: Fabian K.
Location: Switzerland
Contact:

Re: List all Replica VMs

Post by Mildur »

Hello Quentin

I have moved your question to this existing topic.
Can you please try Olegs suggestion?

Code: Select all

$replicas = Get-VBRReplica | Select Name
$replicas = $replicas.Name
ForEach ($replica in $replicas) { Get-VBRJobObject -Job $replica}
Best,
Fabian
Product Management Analyst @ Veeam Software
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests