Get average times from Veeam via PS

PowerShell script exchange

Get average times from Veeam via PS

Veeam Logoby Markol » Wed Jan 15, 2014 12:18 pm

Hi all,

I found a great script on the web for collecting in times/duration and so on forth.

But the downside in the script is that it only collects a number of jobs back in time. What I need would that I can set a date instead fo number of jobs. Anyone that can help me with this?

The code:

Code: Select all
$style = @"
<style>
TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH{border-width: 1px;padding: 2px;border-style: solid;border-color: black;background-color:orange}
TD{border-width: 1px;padding: 2px;border-style: solid;border-color: black;background-color:lightblue}
tr.special {background: #000080;} <tr class="special"></tr>
</style>
"@

$Report = @()
$Jobs = Get-VBRJob -Name "Daily_Bre*"

foreach ($job in $Jobs) {
    $jobName = $job.Name
    $table = New-Object system.Data.DataTable "$table01"
   
   
    $col1 = New-Object system.Data.DataColumn Index,([int])
    $col2 = New-Object system.Data.DataColumn JobName,([string])
    $col3 = New-Object system.Data.DataColumn StartTime,([DateTime])
    $col4 = New-Object system.Data.DataColumn StopTime,([DateTime])
    $col5 = New-Object system.Data.DataColumn FileName,([string])
    $col6 = New-Object system.Data.DataColumn CreationTime,([DateTime])
    $col7 = New-Object system.Data.DataColumn AvgSpeedMB,([int])
    $col8 = New-Object system.Data.DataColumn Duration,([TimeSpan])
    $col9 = New-Object system.Data.DataColumn Result,([String])

    $table.columns.add($col1)
    $table.columns.add($col2)
    $table.columns.add($col3)
    $table.columns.add($col4)
    $table.columns.add($col5)
    $table.columns.add($col6)
    $table.columns.add($col7)
    $table.columns.add($col8)
    $table.columns.add($col9)
   

   
    $session = Get-VBRBackupSession | ?{$_.JobId -eq $job.Id} | %{
            $row = $table.NewRow()
            $row.JobName = $_.JobName
            $row.StartTime = $_.CreationTime
            $row.StopTime = $_.EndTime
            #Work out average speed in MB and round this to 0 decimal places, just like the Veeam GUI does.
         $row.AvgSpeedMB = [Math]::Round($_.Progress.AvgSpeed/1024/1024,0)
           
         $row.Duration = '{0:00}:{1:00}:{2:00}' -f $_.Progress.Duration.Hours, $_.Progress.Duration.Minutes, $_.Progress.Duration.Seconds
           
            if ($_.Result -eq "Failed") {
                    #This is highlight is going to later be searched and replaced with HTML code to highlight failed jobs in RED :)
               $row.Result = "#HIGHLIGHTRED"+$_.Result+"HIGHLIGHTRED#"
                } else {
                   
               $row.Result = $_.Result
               }
            #Add this calculated row to the $table.Rows
         $table.Rows.Add($row)
        }

   
   $interestingsess = $table | Sort StartTime -descending | select -first 7

    $pkc = 1
    $interestingsess | foreach {
      
      $_.Index = $pkc
      #Increment $pkc, so the next foreach loop assigns a higher value to the next .Index property on the next row.
      $pkc+=1
   }
   
   
   $backup = Get-VBRBackup | ?{$_.JobId -eq $job.Id}
    $points = $backup.GetStorages() | sort CreationTime -descending | Select -First 7
   $ic = 1
    ForEach ($point in $points) {
             $rows = $table | ?{$_.Index -eq $ic}
       #inner ForEach loop to assign the value of the backup point's filename to the row's .FileName property as well as the creation time.
      ForEach ($row in $rows) {
          ($row.FileName = $point.FileName) -and ($row.CreationTime = $point.CreationTime)
        #Increment the $ic variable ( +1 )
        $ic+=1
       
       }
    }
   #Tally up the current results into our $Report Array (add them)
    $Report += $interestingsess
}


#Now we select those values of interest to us and convert the lot into HTML, assigning the styling we defined at the beginning of this script too.
$Report = $Report | Select Index, JobName, StartTime, StopTime, FileName, CreationTime, AvgSpeedMB, Duration, Result | ConvertTo-HTML -head $style

#Interesting bit - replace the highlighted parts with HTML code to flag up Failed jobs.
$Report = $Report -replace "#HIGHLIGHTRED","<font color='red'><B>"
$Report = $Report -replace "HIGHLIGHTRED#","</font></B>"
#Finally, save the report to a file on your drive.
$Report | Set-Content C:\Veeam-Backup-Report.htm
Markol
Enthusiast
 
Posts: 26
Liked: 2 times
Joined: Fri Apr 20, 2012 12:12 pm
Full Name: Marko Lehto

Re: Get average times from Veeam via PS

Veeam Logoby v.Eremin » Wed Jan 15, 2014 1:25 pm

Hi, Marko, could elaborate on what you're trying to achieve? You want to output information regarding job sessions for "last X days" or something different?

Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Get average times from Veeam via PS

Veeam Logoby nefes » Wed Jan 15, 2014 1:34 pm

If I understand you correctly, you need to replace
$points = $backup.GetStorages() | sort CreationTime -descending | Select -First 7
with
$points = $backup.GetStorages() | sort CreationTime -descending | Where-Object {$_.CreationTime -gt <insert your date here>}
for example, if you need fixed date, it can be
$points = $backup.GetStorages() | sort CreationTime -descending | Where-Object {$_.CreationTime -gt "2014-01-01"}
or if you need last 72 hours, it can be
$points = $backup.GetStorages() | sort CreationTime -descending | Where-Object {$_.CreationTime -gt (Get-Date).AddDays(-3)}
nefes
Veeam Software
 
Posts: 534
Liked: 125 times
Joined: Mon Dec 10, 2012 8:44 am
Full Name: Nikita Efes

Re: Get average times from Veeam via PS

Veeam Logoby Markol » Wed Jan 15, 2014 1:47 pm

v.Eremin wrote:Hi, Marko, could elaborate on what you're trying to achieve? You want to output information regarding job sessions for "last X days" or something different?

Thanks.

Yes that's what I trying to get


So
What
nefes wrote:
just wrote might have been the right thing.

Is on the right way I think, going to try this now..
Well the part
Code: Select all
$interestingsess = $table | Sort StartTime -descending | select -first 7
what I think is collecting the last 7 jobs, same as
Code: Select all
$points = $backup.GetStorages() | sort CreationTime -descending | Select -First 7


SO my first quess was that I needed to replace
Code: Select all
$interestingsess = $table | Sort StartTime -descending | select -first 7
with something like:
Code: Select all
$interestingsess = $table | Where { ($_.StartTime) -gt (Get-Date 2014-01-01)
or something

I have nerver been writing powershell so pleas bare with me ;) ( don't yell yet :) )
Markol
Enthusiast
 
Posts: 26
Liked: 2 times
Joined: Fri Apr 20, 2012 12:12 pm
Full Name: Marko Lehto

Re: Get average times from Veeam via PS

Veeam Logoby Markol » Wed Jan 15, 2014 2:01 pm

hmm got some errors

Code: Select all
Property 'Index' cannot be found on this object; make sure it exists and is settable.
At C:\Veeam-Backup-Report.ps1:71 char:6
+         $_. <<<< Index = $pkc
    + CategoryInfo          : InvalidOperation: (Index:String) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

You cannot call a method on a null-valued expression.
At C:\Veeam-Backup-Report.ps1:79 char:30
+ $points = $backup.GetStorages <<<< () | sort CreationTime -descending | Where-Object {$_.Creation
Time -gt "2014-01-01"}
    + CategoryInfo          : InvalidOperation: (GetStorages:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Property 'FileName' cannot be found on this object; make sure it exists and is settable.
At C:\Veeam-Backup-Report.ps1:87 char:17
+           ($row. <<<< FileName = $point.FileName) -and ($row.CreationTime = $point.CreationTime)
    + CategoryInfo          : InvalidOperation: (FileName:String) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound
Markol
Enthusiast
 
Posts: 26
Liked: 2 times
Joined: Fri Apr 20, 2012 12:12 pm
Full Name: Marko Lehto

Re: Get average times from Veeam via PS

Veeam Logoby v.Eremin » Wed Jan 15, 2014 2:07 pm

$interestingsess = $table | Where { ($_.StartTime) -gt (Get-Date 2014-01-01)

It depends on what you're trying to achieve. The said line will collect instances that have StartTime parameter greater than 2014-01-01. In other words, it will collect all the instances that has started within from 2014-01-01 to the current date.

Also, don't forget about closing bracket - }.

Code: Select all
$interestingsess = $table | Where { $_.StartTime -gt (Get-Date 2014-01-01)}


Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Get average times from Veeam via PS

Veeam Logoby Markol » Wed Jan 15, 2014 2:15 pm

hehe that's true
v.Eremin
I forgot that one :)

But still errors, I must be doing something very wrong in the script now...

Code: Select all
   
   #$interestingsess = $table | Sort StartTime -descending | select -first 7
$interestingsess = $table | Where { ($_.StartTime) -gt (Get-Date 2014-01-01)}




    $pkc = 1
    $interestingsess | foreach {
      
      $_.Index = $pkc
      #Increment $pkc, so the next foreach loop assigns a higher value to the next .Index property on the next row.
      $pkc+=1
   }
   
   
   $backup = Get-VBRBackup | ?{$_.JobId -eq $job.Id}
    #$points = $backup.GetStorages() | sort CreationTime -descending | Select -First 7
$points = $backup.GetStorages() | sort CreationTime -descending | Where-Object {$_.CreationTime -gt "2014-01-01"}


it must be ome where in this part that needs to be changed to be able to get the jobs from Jan 1 to current day/date.

Due that date string can't be in 2 places? no...
Markol
Enthusiast
 
Posts: 26
Liked: 2 times
Joined: Fri Apr 20, 2012 12:12 pm
Full Name: Marko Lehto

Re: Get average times from Veeam via PS

Veeam Logoby v.Eremin » Wed Jan 15, 2014 2:39 pm

Seems like $interestingsess variable doesn't have .Index parameter, which looks strange because it's clearly set within the script:

Code: Select all
$col1 = New-Object system.Data.DataColumn Index,([int])
$table.columns.add($col2)
$interestingsess = $table | Sort StartTime -descending | select -first 7


I'm wondering what happens, if you input just $interestingsess. What parameters will be shown?

Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Get average times from Veeam via PS

Veeam Logoby Markol » Wed Jan 15, 2014 2:56 pm

I'm not sure that I understand what you mean at the moment..
Markol
Enthusiast
 
Posts: 26
Liked: 2 times
Joined: Fri Apr 20, 2012 12:12 pm
Full Name: Marko Lehto

Re: Get average times from Veeam via PS

Veeam Logoby v.Eremin » Wed Jan 15, 2014 3:24 pm

According to the provided error log, the $interestingsess doesn't have Index parameter. So, if you try to put $interestingsess into the pipeline, what parameters will be shown there?

Image

Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Get average times from Veeam via PS

Veeam Logoby Markol » Wed Jan 15, 2014 3:41 pm

    Property 'Index' cannot be found on this object; make sure it exists and is settable.
    At C:\Veeam-Backup-Report.ps1:72 char:6
    + $_. <<<< Index = $pkc
    + CategoryInfo : InvalidOperation: (Index:String) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

    You cannot call a method on a null-valued expression.
    At C:\Veeam-Backup-Report.ps1:79 char:34
    + $points = $backup.GetStorages <<<< () | sort CreationTime -descending | Select -First 7
    + CategoryInfo : InvalidOperation: (GetStorages:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    Property 'FileName' cannot be found on this object; make sure it exists and is settable.
    At C:\Veeam-Backup-Report.ps1:88 char:17
    + ($row. <<<< FileName = $point.FileName) -and ($row.CreationTime = $point.CreationTime)
    + CategoryInfo : InvalidOperation: (FileName:String) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound
Markol
Enthusiast
 
Posts: 26
Liked: 2 times
Joined: Fri Apr 20, 2012 12:12 pm
Full Name: Marko Lehto

Re: Get average times from Veeam via PS

Veeam Logoby Markol » Thu Jan 16, 2014 6:58 am

After a good night sleep I got what you ment by that =) sorry (installed ise.exe)
that parameter don't show anything
Markol
Enthusiast
 
Posts: 26
Liked: 2 times
Joined: Fri Apr 20, 2012 12:12 pm
Full Name: Marko Lehto

Re: Get average times from Veeam via PS

Veeam Logoby Markol » Thu Jan 16, 2014 8:01 am

The info that
Code: Select all
$interestingsess = $table | Sort StartTime -descending | select -first 1

Shows. Is the same in
Code: Select all
$interestingsess


    Index : 1
    JobName : Daily
    StartTime : 2014-01-15 19:30:09
    StopTime : 2014-01-15 19:42:34
    FileName : Daily2014-01-15T193037.vbk
    CreationTime : 2014-01-15 19:30:37
    AvgSpeedMB : 729
    Duration : 00:12:24
    Result : Success
Markol
Enthusiast
 
Posts: 26
Liked: 2 times
Joined: Fri Apr 20, 2012 12:12 pm
Full Name: Marko Lehto

Re: Get average times from Veeam via PS

Veeam Logoby v.Eremin » Thu Jan 16, 2014 9:56 am

Hi, Marko, can you post here the modified version of the script - the exact version you're trying to run in your environment? It's still not clear (at least, for me) why Index property can't be found, even though it's explicitly set and can be even seen.

Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Get average times from Veeam via PS

Veeam Logoby Markol » Thu Jan 16, 2014 10:09 am

Sure, here it is, I ran this now and got some errors..
Code: Select all
$style = @"
<style>
TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
TH{border-width: 1px;padding: 2px;border-style: solid;border-color: black;background-color:orange}
TD{border-width: 1px;padding: 2px;border-style: solid;border-color: black;background-color:lightblue}
tr.special {background: #000080;} <tr class="special"></tr>
</style>
"@
#asnp VeeamPSSnapin

$Report = @()
$Jobs = Get-VBRJob -Name "Daily_Ly*"

foreach ($job in $Jobs) {
    $jobName = $job.Name
    $table = New-Object system.Data.DataTable "$table01"
   
   
    $col1 = New-Object system.Data.DataColumn Index,([int])
    $col2 = New-Object system.Data.DataColumn JobName,([string])
    $col3 = New-Object system.Data.DataColumn StartTime,([DateTime])
    $col4 = New-Object system.Data.DataColumn StopTime,([DateTime])
    $col5 = New-Object system.Data.DataColumn FileName,([string])
    $col6 = New-Object system.Data.DataColumn CreationTime,([DateTime])
    $col7 = New-Object system.Data.DataColumn AvgSpeedMB,([int])
    $col8 = New-Object system.Data.DataColumn Duration,([TimeSpan])
    $col9 = New-Object system.Data.DataColumn Result,([String])

    $table.columns.add($col1)
    $table.columns.add($col2)
    $table.columns.add($col3)
    $table.columns.add($col4)
    $table.columns.add($col5)
    $table.columns.add($col6)
    $table.columns.add($col7)
    $table.columns.add($col8)
    $table.columns.add($col9)
   

   
    $session = Get-VBRBackupSession | ?{$_.JobId -eq $job.Id} | %{
            $row = $table.NewRow()
            $row.JobName = $_.JobName
            $row.StartTime = $_.CreationTime
            $row.StopTime = $_.EndTime
            #Work out average speed in MB and round this to 0 decimal places, just like the Veeam GUI does.
         $row.AvgSpeedMB = [Math]::Round($_.Progress.AvgSpeed/1024/1024,0)
           
         $row.Duration = '{0:00}:{1:00}:{2:00}' -f $_.Progress.Duration.Hours, $_.Progress.Duration.Minutes, $_.Progress.Duration.Seconds
           
            if ($_.Result -eq "Failed") {
                    #This is highlight is going to later be searched and replaced with HTML code to highlight failed jobs in RED :)
               $row.Result = "#HIGHLIGHTRED"+$_.Result+"HIGHLIGHTRED#"
                } else {
                   
               $row.Result = $_.Result
               }
            #Add this calculated row to the $table.Rows
         $table.Rows.Add($row)
        }

   
   $interestingsess = $table | Sort StartTime -descending | select -first 7
        #$interestingsess
#$interestingsess = $table | Where { ($_.StartTime) -gt (Get-Date 2014-01-01)}




    $pkc = 1
    $interestingsess | foreach {
      
      $_.Index = $pkc
      #Increment $pkc, so the next foreach loop assigns a higher value to the next .Index property on the next row.
      $pkc+=1
   }
   
   
   $backup = Get-VBRBackup | ?{$_.JobId -eq $job.Id}
    $points = $backup.GetStorages() | sort CreationTime -descending | Select -First 7
#$points = $backup.GetStorages() | sort CreationTime -descending | Where-Object {$_.CreationTime -gt "2014-01-01"}


   $ic = 1
    ForEach ($point in $points) {
             $rows = $table | ?{$_.Index -eq $ic}
       #inner ForEach loop to assign the value of the backup point's filename to the row's .FileName property as well as the creation time.
      ForEach ($row in $rows) {
          ($row.FileName = $point.FileName) -and ($row.CreationTime = $point.CreationTime)
        #Increment the $ic variable ( +1 )
        $ic+=1
       
       }
    }
   #Tally up the current results into our $Report Array (add them)
    $Report += $interestingsess
}


#Now we select those values of interest to us and convert the lot into HTML, assigning the styling we defined at the beginning of this script too.
$Report = $Report | Select Index, JobName, StartTime, StopTime, FileName, CreationTime, AvgSpeedMB, Duration, Result | ConvertTo-HTML -head $style

#Interesting bit - replace the highlighted parts with HTML code to flag up Failed jobs.
$Report = $Report -replace "#HIGHLIGHTRED","<font color='red'><B>"
$Report = $Report -replace "HIGHLIGHTRED#","</font></B>"
#Finally, save the report to a file on your drive.
$Report | Set-Content C:\Veeam-Backup-Report.htm



The errors:

Code: Select all
Property 'Index' cannot be found on this object; make sure it exists and is settable.
At C:\Veeam-Backup-Report.ps1:73 char:6
+         $_. <<<< Index = $pkc
    + CategoryInfo          : InvalidOperation: (Index:String) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound
 
You cannot call a method on a null-valued expression.
At C:\Veeam-Backup-Report.ps1:80 char:34
+     $points = $backup.GetStorages <<<< () | sort CreationTime -descending | Select -First 7
    + CategoryInfo          : InvalidOperation: (GetStorages:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
Property 'FileName' cannot be found on this object; make sure it exists and is settable.
At C:\Veeam-Backup-Report.ps1:89 char:17
+           ($row. <<<< FileName = $point.FileName) -and ($row.CreationTime = $point.CreationTime)
    + CategoryInfo          : InvalidOperation: (FileName:String) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound
 
Property 'FileName' cannot be found on this object; make sure it exists and is settable.
At C:\Veeam-Backup-Report.ps1:89 char:17
+           ($row. <<<< FileName = $point.FileName) -and ($row.CreationTime = $point.CreationTime)
    + CategoryInfo          : InvalidOperation: (FileName:String) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

A lot of the last part, took them away
Markol
Enthusiast
 
Posts: 26
Liked: 2 times
Joined: Fri Apr 20, 2012 12:12 pm
Full Name: Marko Lehto

Next

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 5 guests