PowerShell script exchange
Post Reply
theadamlion
Service Provider
Posts: 17
Liked: 5 times
Joined: Feb 02, 2022 2:24 pm
Full Name: Adam Lion
Contact:

Script to find all jobs assigned to a given proxy - inverse of Get-VBRJobProxy

Post by theadamlion »

Hello all, I've been trying to find a command or script that does the opposite of the Get-VBRJobProxy command.

That command will take a given job name and return the list of all proxies available to the job- what I am hoping to find is the opposite of that. I'd like to be able to give the name of a specific proxy and have it spit out the jobs that are associated with/assigned to that proxy.

Any chance someone has something for this or some ideas? Thanks all.

-Adam
HannesK
Product Manager
Posts: 14844
Liked: 3086 times
Joined: Sep 01, 2014 11:46 am
Full Name: Hannes Kasparick
Location: Austria
Contact:

Re: Script to find all jobs assigned to a given proxy - inverse of Get-VBRJobProxy

Post by HannesK »

Hello,
and welcome to the forums.

I would iterate though all backup jobs and compare the proxies configured vs. the proxy you are searching for.

Best regards,
Hannes
theadamlion
Service Provider
Posts: 17
Liked: 5 times
Joined: Feb 02, 2022 2:24 pm
Full Name: Adam Lion
Contact:

Re: Script to find all jobs assigned to a given proxy - inverse of Get-VBRJobProxy

Post by theadamlion »

Hello Hannes, thanks for the info and the welcome! As I am fairly new to the world of Powershell, what would be a good starting point to get familiar with the best to accomplish iterating through the backup jobs and comparing?

I tried something similar to this:

$Jobs = Get-VBRJob
Write-Output $Jobs | Get-VBRJobProxy

While these two lines worked and displayed the assigned proxies for all the current jobs, doing so didn't display the job name in the output. Do you know how I could get the name of the job included in that output? If I could get that going, I could theoretically output everything to a .csv file and filter based on the proxy name.

Thanks again Hannes!

-Adam
david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Script to find all jobs assigned to a given proxy - inverse of Get-VBRJobProxy

Post by david.domask »

Hey Adam,

You'll need to loop over your jobs and then create a PSCustomObject to add to some array. Try:

Code: Select all

$JobProxyArray = @()
foreach($j in $jobs){
     $proxy = Get-VBRJobProxy -Job $j -WarningAction SilentlyContinue
     $JobProxyInfo = [PSCustomObject]@{
          JobName = $j.name
          Proxies = ($proxy.Name -Join ",")
     }
     $JobProxyArray += $JobProxyInfo
}
This will make a custom object $JobProxyArray with all your relevant info.

From there, you can use Export-CSV to get it to CSV. Make sure to include the -NoTypeInformation flag else PS will dump info on the Array type.

I do want to warn though that this is a very basic approach, and there are some nuances to consider.

1. If Auto-Detect is enabled (i.e., automatic selection), it will return all possible proxies. I recommend add a logic into the loop that checks the value of SourceProxyAutoDetect, and if $true, consider setting Proxies to some special value.
2. This method will create two columns for your CSV, so your CSV might have a fairly "loaded" column; make sure whatever processes your CSV can handle that accordingly. Getting a column for each proxy returned is possible, but this takes a bit.
3. Get-VBRJob can return a lot of job types, so you might want to add parsing on the $j.JobType or add it as a property to $JobproxyInfo. I think you can see from my example how to build additional properties from the Job Object and the Proxy object it builds inside the loop.

Hope it helps.
David Domask | Product Management: Principal Analyst
theadamlion
Service Provider
Posts: 17
Liked: 5 times
Joined: Feb 02, 2022 2:24 pm
Full Name: Adam Lion
Contact:

Re: Script to find all jobs assigned to a given proxy - inverse of Get-VBRJobProxy

Post by theadamlion »

Hey David, thank you kindly for the reply and for the example! That is incredibly helpful and I will give this a shot later on and test it out. This is some helpful info to get started with PowerShell, thank you much for the assist!

-Adam
Post Reply

Who is online

Users browsing this forum: No registered users and 17 guests