PowerShell script exchange
Post Reply
sidavid
Enthusiast
Posts: 63
Liked: 1 time
Joined: Jan 01, 2006 1:01 am
Contact:

Change Proxy in Jobs

Post by sidavid »

Hi

I want to change the proxy setting of several jobs and specified a proxy:

Code: Select all

Add-PSSnapin "VeeamPSSnapIn"
Get-VBRJob | where {$_.name.StartsWith("JobName")} | foreach {
$vbrjobname = $_.Name
$job = Get-VBRJob | ?{$_.Name -eq $vbrjobname}
$vo = $job.GetOptions()
$vo.JobOptions.SourceProxyAutoDetect = $False
$proxy = Get-VBRViProxy -name "backupproxy1"
$Type = [Veeam.Backup.Model.CJobProxyInfo+EType]::ESource
[Veeam.Backup.Core.CJobProxy]::Create($job.id, $proxy.id, $type)
$job.SetOptions($vo)
}
With this script, the backup proxy setting is set to use the backup proxy servers specified below but all the proxys are checked, I want to uncheck all and specified mine. Is it possible?

Many thanks for your help

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

Re: Change Proxy in Jobs

Post by veremin »

Hi, David.

It took me for a little while but I think, I managed to find a solution for your issue.
So, here it’s with some commentary.

Code: Select all

asnp VeeamPSSnapin

#First part of the script is responsible for disabling SourceProxyAutoDetection

$Job = Get-VBRJob | ?{$_.Name –eq “Name of your Job”}
$vo= $job.GetOptions()
$vo.JobOptions.SourceProxyAutoDetect = $False
$job.SetOptions($vo)

#After having done that, our goal is to exclude from our job all proxies except for one. 
#Thus, second part of the script is checking proxies which names don't coincide with the name of the proxy we're going to leave.
#The result of that process is being saved in $Proxies list.
#In the end, within the cycle, we delete all of such proxies, meanwhile create the only one ($ProxytoAdd).
#Little note: $ProxyType = 0 means SourceProxy, 1 - TargetProxy. 
  
$ProxyType = 0
$ProxyToAdd = Get-VBRViProxy| ?{$_.Name –eq "Name of proxy you're going to leave"}
$Proxies= Get-VbrViProxy | ?{$_.Name –ne $ProxyToAdd}

foreach($ProxytoDelete in $Proxies)
{
    foreach($ProxyInfo in ([Veeam.Backup.DBManager.CDBManager]::Instance.JobProxies.GetJobProxies($Job.id, $ProxyType)))
    {
        if($ProxyInfo.ProxyId -eq $ProxyToDelete.id)
        {
            [Veeam.Backup.DBManager.CDBManager]::Instance.JobProxies.Delete($ProxyInfo.id)
        }
    }
}
[Veeam.Backup.Core.CJobProxy]::Create($Job.id, $ProxyToAdd.id, $ProxyType)
That’s all.

Even though, i've used it in earnest, it's still nothing but draft-work with a lot of space for improvement. Consequently, all commentary is higly-apprecieated.

Feel free to use and/or share it.
And don’t forget to try it before implementing.

Hope this helps.
Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests