PowerShell script exchange
Post Reply
hm-hmason
Novice
Posts: 6
Liked: never
Joined: Sep 19, 2017 1:49 pm
Full Name: Heath Mason
Contact:

PowerShell script to pull backup jobs and related copy/tape jobs

Post by hm-hmason »

Trying to put together a reports of all our backup jobs and all secondary jobs (copy/tape). Looking to see if there's a PowerShell command/script out there that can assist.
david.domask
Veeam Software
Posts: 1226
Liked: 322 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: PowerShell script to pull backup jobs and related copy/tape jobs

Post by david.domask »

Hi @hm-hmason,

Before we get at this with Powershell, may I ask if our VeeamOne report is suitable for you?

https://helpcenter.veeam.com/docs/one/r ... ry&ver=120

I think this is what you're looking for mostly and I think it's easier.

You can pull the individual jobs with the relevant Get cmdlets: https://helpcenter.veeam.com/docs/backu ... er=120#get

So you'd find each type of job and just run those for the list, but I get this might be a bit putzy for normal use.

The main goal is to just find those backups _without_ a secondary target? Or just a job inventory?
David Domask | Product Management: Principal Analyst
hm-hmason
Novice
Posts: 6
Liked: never
Joined: Sep 19, 2017 1:49 pm
Full Name: Heath Mason
Contact:

Re: PowerShell script to pull backup jobs and related copy/tape jobs

Post by hm-hmason »

I am aware that I could probably get what I 'm looking for from Veeam One but unfortunately, we do not have that currently. What I am trying to get is a list of all our backup jobs and a relation to any copy/tape jobs that are associated with them. I'll take a look at the Get cmdlets and see what I can pull. Thanks.
david.domask
Veeam Software
Posts: 1226
Liked: 322 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: PowerShell script to pull backup jobs and related copy/tape jobs

Post by david.domask »

Got it, thanks for the clarification.

You will need to do this "somewhat" backwards, as the relationship with powershell for secondary jobs to source jobs is the LinkedJobs or the LinkedJobIds property of CJob objects.

My examples below are from a Backup Copy job, and I'm checking the Backup Copy for its LinkedJobs and LinkedJobId properties:

Code: Select all

PS C:\Users\Administrator> $job = Get-VBRJob -name 'ps-exclude-test'
PS C:\Users\Administrator> $job.LinkedJobs


Info         : Veeam.Backup.Model.CLinkedObjectInfo
OrderNo      : 0
Id           : 89e7223e-6a7b-482b-92e1-701c3da35cb2
JobId        : de6d2523-0db8-4913-8fd6-56d522efd785
LinkedJobId  : c1b0bf4c-39d2-4ec1-80d6-e4444de078ca
CreationTime : 8/4/2023 1:09:42 PM

PS C:\Users\Administrator> $job.LinkedJobIds

Guid
----
c1b0bf4c-39d2-4ec1-80d6-e4444de078ca

So you will need to design a workflow that:

1. Collects all the source Image Level Backup Jobs to an array $SourceJobs (VMware and HyperV Backups)
2. Collects the secondary jobs (Backup Copies, Tape Jobs) and add them to an array $SecondaryJobs
3. Start an empty array for $JobsAndSecondaryReport
3. Start a ForEach loop over $SourceJobs and check in order:
3a. For Backup Copies Is the current Job ID in the LinkedJobIds or LinkedJobs.JobId lists?
3b. For Tape Jobs, is the current Job ID in the Objects property list? (You may want to build an array of this outside of the ForEach loop for speed purposes, but it's not super expensive call to do in the loop)
3c. If the SourceJob.Id is in either list from 3a or 3b, it means that source job is in secondary jobs, so we will build a PSCustomObject that has three properties:

Source Job Name
Backup Copy Job Name
Tape Job Name

If the source job ID is in either 3a or 3b (or both), you will simply set the property on the PSCustomObject to be that job-name for the relevant property.
3d. Add the resulting PSCustomObject to the $JobsAndSecondaryReport array

Once the Foreach loop is done, you'll have your list of associations from source jobs to secondary.
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests