Same Powershell script runs longer in a different server

I have two windows servers 1 2012R2 powershell version 5.0 2. windows 2016 powershell version 5.1

I use Nagios to monitor my systems. I am on a VMware system both are VM’s

Both run a backup application Veeam B&R

I found a powershell script that checks the backup, replication and copy jobs.

on the Windows 2012R2 server it runs with no issues.

on the windows 2016 server it takes 1 minute 49 seconds to run and it outputs the correct information.

The problem is it runs too long on the Windows 2016 server and Nagios times out and the check fails.

Could it be a problem with 5.1 of powershell?

Any ideas.

Thank you

 

Tom

 

 

 

 

 

The goal is to troubleshoot a script that you are not providing to assist you in your assumption? Determine where exactly the script is actually timing out and troubleshoot it. My guess is line 23…

Here is the script found on the Nagios plugins site

check_veeam_backup.ps1

<

$name = $args[0]

if ((Get-PSSnapin -Name VeeamPSSNapin -ErrorAction SilentlyContinue) -eq $null)

{

Add-PSSnapin VeeamPSSNapin

}

$JobNames = Get-VBRJob -Name $name

foreach ($JobName in $JobNames) {

$Job = Get-VBRJob -name $JobName.Name

$LastSession = $Job.FindLastSession()

$Name = $Job.Name

$Status = $LastSession.State

$Progress = “$($LastSession.BaseProgress)%”

$LastResult = Get-VBRBackupSession | Where {$_.jobId -eq $job.Id.Guid} | Sort EndTimeUTC -Descending | Select -First 1 -ExpandProperty result

}

If ($LastResult = “Success”)
{
write-host $Name $Status $Progress $LastResult
exit 0 #success
}
ELSE {
IF ($LastResult = “None”)
{
write-host $Name $Status $Progress $LastResult
exit 1 #Warning
}
ELSE {
IF ($LastResult = “Error”)
{
write-host $Name $Status $Progress $LastResult
exit 2 #critical
}
ELSE {
write-host $Name $Status $Progress $LastResult
exit 3 #unknown
}
}
}

>

 

 

Thank you

 

Tom

Tom,
you are member of this forum for a quite long time. Is it really necessary to ask you again to format your code as code?



$name = $args[0]



if ((Get-PSSnapin -Name VeeamPSSNapin -ErrorAction SilentlyContinue) -eq $null)



{



Add-PSSnapin VeeamPSSNapin



}



$JobNames = Get-VBRJob -Name $name



foreach ($JobName in $JobNames) {



$Job = Get-VBRJob -name $JobName.Name



$LastSession = $Job.FindLastSession()



$Name = $Job.Name



$Status = $LastSession.State



$Progress = "$($LastSession.BaseProgress)%"



$LastResult = Get-VBRBackupSession | Where {$_.jobId -eq $job.Id.Guid} | Sort EndTimeUTC -Descending | Select -First 1 -ExpandProperty result



}



If ($LastResult = "Success")
{
write-host $Name $Status $Progress $LastResult
exit 0 #success
}
ELSE {
IF ($LastResult = "None")
{
write-host $Name $Status $Progress $LastResult
exit 1 #Warning
}
ELSE {
IF ($LastResult = "Error")
{
write-host $Name $Status $Progress $LastResult
exit 2 #critical
}
ELSE {
write-host $Name $Status $Progress $LastResult
exit 3 #unknown
}
}
}

Olaf

not able to format the code for some reason

You should activate the text view of your new post and simply select the code you just pasted to the edit box of the post editor and click on button named “PRE”.

And please try to avoid posting that much unnecessary white space. Thanks.

This is still going to be difficult to troubleshoot in the forum. Other than some basic edits, you can try this script. The biggest thing is putting Write-Host in the loop so you can see what it’s processing. Not sure why Get-VBRJob is used to get the jobs and then Get-VBRJob again to get the job again, but hopefully the below points you in the right direction:

param(
    [Parameter(Position=0)]
    [String]
    $Name
)

if ((Get-PSSnapin -Name VeeamPSSNapin -ErrorAction SilentlyContinue) -eq $null) {

    Add-PSSnapin VeeamPSSNapin

}

$JobNames = Get-VBRJob -Name $name

foreach ($Job in $JobNames) {

    #$Job = Get-VBRJob -name $JobName.Name
    $LastSession = $Job.FindLastSession()
    $Name = $Job.Name
    $Status = $LastSession.State
    $Progress = "$($LastSession.BaseProgress)%"
    $LastResult = Get-VBRBackupSession | 
                  Where {$_.jobId -eq $job.Id.Guid} | 
                  Sort EndTimeUTC -Descending | 
                  Select -First 1 -ExpandProperty result

    Write-Host $Name $Status $Progress $LastResult
}

switch ($LastResult) {
    "Success"  {
        exit 0 #success
    }
    "None" {
        exit 1 #Warning
    }
    "Error" {
        exit 2 #critical
    }
    default {
        exit 3 #unknown
    }
}

Thanks

ran the sample from you and it took 1min and 16 seconds

PS C:\program files\nsclient++\scripts\powershell> .\check_veeam_bkups.ps1 ‘linux vm backup’
Linux VM Backup Stopped 100% Success

PS C:\program files\nsclient++\scripts\powershell> measure-command {./check_veeam_bkups.ps1 ‘linux vm backup’}
Linux VM Backup Stopped 100% Success

Days : 0
Hours : 0
Minutes : 1
Seconds : 21
Milliseconds : 164
Ticks : 811646305
TotalDays : 0.000939405445601852
TotalHours : 0.0225457306944444
TotalMinutes : 1.35274384166667
TotalSeconds : 81.1646305
TotalMilliseconds : 81164.6305

still long any ideas?

Guys

Update.

It is not the script that is the problem.

I ran just the command get-vbrjob -name 'My job" using measure-command

It took several minutes once it took 26 minutes to complete.

Is there any know issues with power shell version 5.1?

I have another server running powershell version 5.0 and have no issues

This is a windows 2016 server

Should I upgrade powershell?

If the root cause is Get-VBRJob and it’s taking 30 minutes, then the Powershell version is unlikely affecting one cmdlet. Is the Snap-In version the same? DNS Issues? This is understanding how the cmdlet is connecting and getting these jobs to understand the root cause of 30 minutes to do so. Is there a verbose or debug switch on the cmdlet that can provide insight on what it’s doing step by step?

Rob,

Yes the snap-in version is the same both server are running Veeam B&R 10. Only difference is powershell version and OS version.

No DNS issue here the command runs local to the server running Veeam B&R

The Veeam commands are here Get-VBRJob - Veeam Backup PowerShell Reference
I did not see a verbose switch

Any thoughts?