PowerShell script exchange
Post Reply
DomBros
Influencer
Posts: 10
Liked: 1 time
Joined: Mar 17, 2017 12:30 pm
Full Name: Tomasz Dabrowski
Contact:

Is there any way to get Host name from which VM was backuped in Backup Job?

Post by DomBros »

Why:
I am creating Application Group and Sure Job using script (part of the script):

Code: Select all

$TestVM = 'TestVmName'
$VmFromBackup = Find-VBRHvEntity -Name $TestVM
$VirtualLab = Get-VSBHvVirtualLab -Name $VirtualLabName
$AppGroup = Add-VSBHvApplicationGroup -Name $AppGroupName -VmFromBackup $VmFromBackup
$VsbJob = Add-VSBHvJob -Name $SureBackupJobName -VirtualLab $VirtualLab -AppGroup $AppGroup -Description $SureBackupJobDescription
the cmdlet Find-VBRHvEntity returns VMs from all hosts connected to Veeam not only from backup jobs and when I use cmdlet Add-VSBHvApplicationGroup and add this VM to application group and create Sure Backup Job using cmdlet Add-VSBHvJob I'm getting an error that VM id 'xxx' cannot be found.

Using script:

Code: Select all

$jobs = Get-VBRJob | Where-Object -FilterScript { $_.JobType -eq "Backup" }
$VBRJobObject  = $jobs | Get-VBRJobObject
$VBRJobObject.Location
I found that sometimes Location gives me info that I want, but this is not I am looking for.
christophe.niel.AID
Service Provider
Posts: 11
Liked: never
Joined: Jul 25, 2019 1:11 pm
Full Name: Christophe Niel
Contact:

Re: Is there any way to get Host name from which VM was backuped in Backup Job?

Post by christophe.niel.AID »

Hello
as you can setup a backup job to backup VM from anything (pool, datastore, folder, etc...) you won't find VM information in the JOB object, they are discovered at run time.

you will need to get the session for a specific job, here is how to get the last finished backup session for a given $Job :
$session=get-vbrbackupsession | ? jobid -eq $job.id.Guid | Sort EndTimeUTC -Descending | Select -First 1

next you need to get the TASKS :
$tasks = $sessions|Get-VBRTaskSession

each task name is the name of a VM (probably, I didn't have any other output on my various setups)

$tasks.name
will give you the list of the all VM Name that were in that specific job (and you can even get the backup status)

if you want more VM information, you need powercli from vmware to get ID or guest host name.

I hope this helps
veremin
Product Manager
Posts: 20400
Liked: 2298 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Is there any way to get Host name from which VM was backuped in Backup Job?

Post by veremin »

Or you can:

- Get backup job (Get-VBRJob)
- Get backup job object (Get-VBRJobObject)
- Find unique VM identifier (be it Id or name)
- Use it as filter parameter to locate VM objects (Find-VBRHvEntity)

Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests