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

List all Replica VMs

Post by digitalexpl0it » Oct 14, 2019 11:32 pm

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: 140
Liked: 15 times
Joined: Aug 28, 2013 8:23 am
Full Name: Petr
Location: Prague, Czech Republic
Contact:

Re: List all Replica VMs

Post by PetrM » Oct 14, 2019 11:47 pm

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: 2 times
Joined: Jul 21, 2016 1:31 am
Full Name: Derrick Rose
Contact:

Re: List all Replica VMs

Post by digitalexpl0it » Oct 15, 2019 12:09 am

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: 2 times
Joined: Jul 21, 2016 1:31 am
Full Name: Derrick Rose
Contact:

Re: List all Replica VMs

Post by digitalexpl0it » Oct 15, 2019 12:13 am

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: 17000
Liked: 1455 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: List all Replica VMs

Post by veremin » Oct 15, 2019 10:16 am 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: 30
Liked: 12 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: List all Replica VMs

Post by oleg.feoktistov » Oct 15, 2019 1:42 pm

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: 2 times
Joined: Jul 21, 2016 1:31 am
Full Name: Derrick Rose
Contact:

Re: List all Replica VMs

Post by digitalexpl0it » Oct 15, 2019 3:16 pm

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: 2 times
Joined: Jul 21, 2016 1:31 am
Full Name: Derrick Rose
Contact:

Re: List all Replica VMs

Post by digitalexpl0it » Oct 15, 2019 3:17 pm

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: 2 times
Joined: Jul 21, 2016 1:31 am
Full Name: Derrick Rose
Contact:

Re: List all Replica VMs

Post by digitalexpl0it » Oct 15, 2019 3:26 pm

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: 17000
Liked: 1455 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: List all Replica VMs

Post by veremin » Oct 16, 2019 5:35 pm 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: 2 times
Joined: Jul 21, 2016 1:31 am
Full Name: Derrick Rose
Contact:

Re: List all Replica VMs

Post by digitalexpl0it » Oct 16, 2019 5:44 pm

Thanks, I will try that

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests