PowerShell script exchange
Post Reply
Eric F.
Influencer
Posts: 13
Liked: never
Joined: Jun 13, 2024 3:57 pm
Full Name: John Forman
Contact:

Changes to PowerShell syntax after upgrade to 12.3

Post by Eric F. »

We have 2 scripts that have been used to remove then add proxy servers to jobs for an migration of proxy servers when we decommissioned 2 servers then added 2 new ones. The scripts worked great and saved us a ton of time.

We are now being asked to rename all of our proxy servers to generic names to be more in line with Veeam best practices (for example: VEPROXY06 to Server345).

The scripts no longer work since we have upgraded to 12.3. Does anyone know what changes have been made, or maybe depreciated, that we will need to update to get the scripts to work again? We have an open Veeam ticket on this, but last time we had an error they stated that PowerShell is provided as-is with no support for making or adjusting scripts (Case #07581663 -- Issue with a PowerScript to remove proxies from Backup Jobs).

Here are the scripts we are using:

Add Proxy

$newproxy = Get-VBRVIProxy -Name "SERVER354"
$jobs = Get-VBRJob | where {$_.TypetoString -eq "VmWare Backup"}
foreach ($job in $jobs)
{
$usedProxy = Get-VBRJobProxy -Job $job

$proxylist = $usedProxy + $newproxy

Set-VBRJobProxy -Job $job -Proxy $proxylist
}



Remove Proxy

$alljobs = Get-VBRJob

foreach ($job in $alljobs) {
[System.Collections.ArrayList]$origproxies = $job | Get-VBRJobProxy | foreach { $_ | Select-Object -ExpandProperty Name}
$origproxies.Remove('dev-vproxy3')
$newproxies = Get-VBRViProxy -Name $origproxies
$job | Set-VBRJobProxy -Proxy $newproxies
}



Thanks in advance for any help that you can provide.
david.domask
Veeam Software
Posts: 2744
Liked: 630 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Changes to PowerShell syntax after upgrade to 12.3

Post by david.domask »

Hi John,

Can you clarify which part of your script is not working? Does it return an error or the script completes but does not make the desired changes?



The correct way to do this is with Set-VBRJobProxy. See the note here:
To modify settings, specify new values for the necessary parameters. The cmdlet will overwrite the previous parameter values with new values. The parameters that you omit will remain unchanged.
Does it work if you build a new array of proxies to add to the job, and use Set-VBRJobProxy and pass your array of proxies.

Sample workflow:

Code: Select all

$job = Get-VBRJob -Name "name of job"
$newProxy = @()
$newProxy =+ Get-VBRViProxy -Name "Proxy001"
$newProxy =+ Get-VBRViProxy -Name "Proxy002"
Set-VBRJobProxy -Job $job -Proxy $newProxy
Works in lab both for adding new proxies and removing proxies, but perhaps you can share the full error you're getting and on which part of the script it fails.
David Domask | Product Management: Principal Analyst
Eric F.
Influencer
Posts: 13
Liked: never
Joined: Jun 13, 2024 3:57 pm
Full Name: John Forman
Contact:

Re: Changes to PowerShell syntax after upgrade to 12.3

Post by Eric F. »

Update:

I updated the 'add' script to:

Code: Select all

$newproxy = Get-VBRVIProxy -Name "SERVER345.bks.one.xxxxx.xxx"
$jobs = Get-VBRComputerBackupJob | where {$_.TypetoString -eq "VmWare Backup"}
foreach ($job in $jobs){
       $usedProxy = Get-VBRJobProxy -Job $job
       $proxylist = $usedProxy + $newproxy
       Set-VBRJobProxy -Job $job -Proxy $proxylist}
And we are getting an error of:

Code: Select all

+ foreach ($job in $jobs)
+            ~
Missing statement in body in foreach loop.
     +CategoryInfo            : ParserError: (:) [], ParentContainsErrorRecordException
     + FullyQualifiedErrorID : MissingForeachStatement
Hope this helps in troubleshooting the 'add' script.
david.domask
Veeam Software
Posts: 2744
Liked: 630 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Changes to PowerShell syntax after upgrade to 12.3

Post by david.domask »

Looking quick at the script, I think this one errored out because you used Get-VBRComputerBackupJob to populate jobs -- Get-VBRCOmputerBackupJob is for Agent-based backups and doesn't have a typetostring value of Vmware Backup. Please try it again with Get-VBRJob instead.
David Domask | Product Management: Principal Analyst
Eric F.
Influencer
Posts: 13
Liked: never
Joined: Jun 13, 2024 3:57 pm
Full Name: John Forman
Contact:

Re: Changes to PowerShell syntax after upgrade to 12.3

Post by Eric F. »

Thank you for the clarification on the 'get-vbrjob" cmdlet.

I re-ran the script with the proper cmdlet and while we didn't get any errors, the new proxy was not set on all the jobs:

Code: Select all

$newproxy = Get-VBRVIProxy -Name "SERVER345.bks.one.xxxxx.xxx"
$jobs = Get-VBRJob | where {$_.TypetoString -eq "VmWare Backup"}
foreach ($job in $jobs){
$usedProxy = Get-VBRJobProxy -Job $job
$proxylist = $usedProxy + $newproxy
Set-VBRJobProxy -Job $job -Proxy $proxylist}
david.domask
Veeam Software
Posts: 2744
Liked: 630 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Changes to PowerShell syntax after upgrade to 12.3

Post by david.domask »

Thanks for the update John.

Can you maybe pick a few jobs and run the script line by line without the foreach Loop? I've just tried reproducing your issue in my lab environment and I cannot, the script works each time.

Check the contents of each variable as you save it, something must not be getting populated but cannot tell what at the moment.
David Domask | Product Management: Principal Analyst
Eric F.
Influencer
Posts: 13
Liked: never
Joined: Jun 13, 2024 3:57 pm
Full Name: John Forman
Contact:

Re: Changes to PowerShell syntax after upgrade to 12.3

Post by Eric F. »

Ok, I got it!
The only thing I am missing is to add an array to add multiple at a time, but I ran the script multiple times with the different proxy names it added them one by one to all VMWare proxy jobs; which is fine by me.

Now I just need to figure out how to edit our remove script to un-select the old proxy servers so we can delete them from the backup infrastructure. May I post here again if I need help with that?
Eric F.
Influencer
Posts: 13
Liked: never
Joined: Jun 13, 2024 3:57 pm
Full Name: John Forman
Contact:

Re: Changes to PowerShell syntax after upgrade to 12.3

Post by Eric F. »

Ok, something else we are running into is the addition and removal of proxy servers as "Guest Interaction Proxy" settings. Is there a way to add / remove proxy servers from this function of the job by chance?

I am not seeing anything in the Veeam PowerShell reference that looks like it would apply.
david.domask
Veeam Software
Posts: 2744
Liked: 630 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Changes to PowerShell syntax after upgrade to 12.3

Post by david.domask »

Hi John,

Glad I could help, and sure, feel free to post any questions about your Veeam powershell scripts, we'll do our best to help :)

>addition and removal of proxy servers as "Guest Interaction Proxy" settings. Is there a way to add / remove proxy servers from this function of the job by chance?

At this time no, any managed Windows server in Veeam is automatically eligible to perform Guest Interaction Proxy role, however you can configure the job to only use specific Guest Interaction Proxies.

The unsupported method here still works in 12.3, and unfortunately is the only way to set the Guest Interaction Proxy settings programmatically, but it should be safe to use.
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 12 guests