PowerShell script exchange
Post Reply
l0stb@ackup
Influencer
Posts: 14
Liked: 4 times
Joined: Jul 19, 2018 2:10 am
Contact:

Getting source VMs/tags of all jobs

Post by l0stb@ackup »

Hello,

We have multiple jobs and I need to create a list of the source VMs/tags per job.

Following basic research I tried running this command:

Code: Select all

Get-VBRJob -Name jobname | Get-VBRJobObject | select object
The problem is that this command lists the correct source (vmware tag) plus many other individual VMs that are not present in the Virtual Machines section of the job in the GUI.

Is there a reliable way I can extract this info from all jobs?

Thanks in advance
veremin
Product Manager
Posts: 20284
Liked: 2258 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Getting source VMs/tags of all jobs

Post by veremin »

Hmm, looks unexpected as only source tag object should be returned.

However, if you only include tags as the job source, you can easily filter out unnecessary VM, using something similar:

Code: Select all

$Job | Get-VBRJobobject | where {$_.GetObject().Type -ne "VM"}
Thanks!
l0stb@ackup
Influencer
Posts: 14
Liked: 4 times
Joined: Jul 19, 2018 2:10 am
Contact:

Re: Getting source VMs/tags of all jobs

Post by l0stb@ackup »

Thanks I tried that but it returns nothing:

Code: Select all

PS C:\Users\user> Get-VBRJob -Name jobname | Get-VBRJobobject | where {$_.GetObject().Type -ne "VM"}

PS C:\Users\user>
I guess the problem is that Get-VBRJobobject returns multiple "object" objects: one with the correct source tag and all others with incorrect individual VMs
veremin
Product Manager
Posts: 20284
Liked: 2258 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Getting source VMs/tags of all jobs

Post by veremin »

Hmm, strange. Can you provide the output of the following code:

Code: Select all

Get-VBRJob -Name jobname | Get-VBRJobobject | select name, {$_.GetObject().Type}
Or

Code: Select all

Get-VBRJob -Name jobname | Get-VBRJobobject 

Thanks!
l0stb@ackup
Influencer
Posts: 14
Liked: 4 times
Joined: Jul 19, 2018 2:10 am
Contact:

Re: Getting source VMs/tags of all jobs

Post by l0stb@ackup »

Thanks v.Eremin, have PMed you with the output
veremin
Product Manager
Posts: 20284
Liked: 2258 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Getting source VMs/tags of all jobs

Post by veremin »

Checked the output, now I think that I've managed to find a way to return only tag objects. See this example:

Code: Select all

$Job | Get-VBRJobObject | where {$_.GetObject().Info.ViType -eq "Tag"} | select name
Thanks!
l0stb@ackup
Influencer
Posts: 14
Liked: 4 times
Joined: Jul 19, 2018 2:10 am
Contact:

Re: Getting source VMs/tags of all jobs

Post by l0stb@ackup »

Thank you

Your code works and I created a PowerShell script which loops through all jobs and gets this info. I sent you the code with the output in a PM. Please also review my in-script comments.

Of course the challenge with your above line is that source tags and source VMs cannot be reliably differentiated as they seem to fall under the same object category. For example a job that has both a tag and individual VMs in its source is going to be tricky to report on. is there a "{$_.GetObject().Info.ViType -eq "VM"}"? When I run this I get nothing:

Code: Select all

$job | Get-VBRJobObject | select $_.GetObject | select Info | select ViType
veremin
Product Manager
Posts: 20284
Liked: 2258 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Getting source VMs/tags of all jobs

Post by veremin »

Basically, if only tag is selected as a source job object, no VMs should be returned when you run this command:

Code: Select all

$Job = Get-VBRJob -name "Name of your Backup job"
$Job | Get-VBRJobobject
If both tag and VMs are added to a backup job and you want to differentiate between them, then, it makes sense to output object type along with object name:

Code: Select all

$Job = Get-VBRJob -name "Name of your Backup job"
($Job | Get-VBRJobobject).GetObject().info | select name, ViType
Thanks!
l0stb@ackup
Influencer
Posts: 14
Liked: 4 times
Joined: Jul 19, 2018 2:10 am
Contact:

Re: Getting source VMs/tags of all jobs

Post by l0stb@ackup »

I can confirm that when I run this code against a job with only one tag in the source list, the output returned contains both the tag and VM objects that are members of the tag.
veremin
Product Manager
Posts: 20284
Liked: 2258 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Getting source VMs/tags of all jobs

Post by veremin »

Cannot confirm the issue in my lab, it might stand to reason to reach our support team for further clarification - might be something environment-specific. Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests