PowerShell script exchange
Post Reply
csaumure
Lurker
Posts: 2
Liked: never
Joined: Mar 01, 2020 6:00 am
Full Name: Cory
Contact:

Confirm backup success then execute command

Post by csaumure »

I am trying to get a script to work with all our veeam replica jobs to confirm success or warning and if successful to execute a command.

I have this working for a test server but for some reason i have tried running this in my production and I get an error.

Here is my PS script
Add-PSSnapin VeeamPSSnapin
$VBRBackupJobName = "Replica Jobname"
$VBRLastBackupSuccess = (Get-VBRJob | where {$_.Name -eq $VBRBackupJobName}).GetLastResult() -eq "Success" -OR (Get-VBRJob | where {$_.Name -eq $VBRBackupJobName}).GetLastResult() -eq "Warning"
If(!$VBRLastBackupSuccess)
{ Exit }
else
{Invoke-Command -ComputerName SERVERHOSTNAME -ScriptBlock {Remove-Item -Path HKLM:\Software\Kaseya\Agent\SkipAutoUpdate -Confirm:$false}}

The error I get when running this is as follows:

You cannot call a method on a null-valued expression.
At C:\VeeamScripts\Veeam - ConfirmSuccess SERVERHOSTNAME.ps1:3 char:1
+ $VBRLastBackupSuccess = (Get-VBRJob | where {$_.Name -eq $VBRBackupJo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

Any help would be greatly appreciated.
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Confirm backup success then execute command

Post by oleg.feoktistov »

Hi Cory,

Cannot test your script right away to say for sure, but from what the error tells,
Get-VBRJob cmdlet failed to resolve a job with the name specified.
And no method can be called on the null output.
I would also organize the code itself in a way, which would be convenient for further debugging:

Code: Select all

$VBRBackupJobName = "Replica Jobname"
$VBRJob = Get-VBRJob | where {$_.Name -eq $VBRBackupJobName}
$VBRLastBackupSuccess = $VBRJob.GetLastResult()
If(!$VBRLastBackupSuccess)
{ Exit }
elseif ($VBRLastBackupSuccess -eq 'Success' -or $VBRLastBackupSuccess -eq 'Warning') {
Invoke-Command -ComputerName SERVERHOSTNAME -ScriptBlock {Remove-Item -Path HKLM:\Software\Kaseya\Agent\SkipAutoUpdate -Confirm:$false}
}
Will test it tomorrow at the office, though.

Thanks,
Oleg
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Confirm backup success then execute command

Post by oleg.feoktistov »

Just tested your script. Works with a right name and doesn't work as soon as I assign non-existing job name value to $VBRBackupJobName.
csaumure
Lurker
Posts: 2
Liked: never
Joined: Mar 01, 2020 6:00 am
Full Name: Cory
Contact:

Re: Confirm backup success then execute command

Post by csaumure »

Ill double check the file but thought I went into the job.jobname.txt file and confirmed the job name in there.
But certainly good to know you did get it working.

I appreciate your time testing and confirming for me. I'll update you on whether I had some sort of typo but I had this occur on multiple jobs so thought maybe the code was not setup right.
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests