PowerShell script exchange
Post Reply
Markol
Enthusiast
Posts: 26
Liked: 2 times
Joined: Apr 20, 2012 12:12 pm
Full Name: Marko Lehto
Contact:

Get average times from Veeam via PS

Post by Markol » 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

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

Re: Get average times from Veeam via PS

Post by veremin » 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.

nefes
Veeam Software
Posts: 628
Liked: 156 times
Joined: Dec 10, 2012 8:44 am
Full Name: Nikita Efes
Contact:

Re: Get average times from Veeam via PS

Post by nefes » 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)}

Markol
Enthusiast
Posts: 26
Liked: 2 times
Joined: Apr 20, 2012 12:12 pm
Full Name: Marko Lehto
Contact:

Re: Get average times from Veeam via PS

Post by Markol » 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: Apr 20, 2012 12:12 pm
Full Name: Marko Lehto
Contact:

Re: Get average times from Veeam via PS

Post by Markol » 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

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

Re: Get average times from Veeam via PS

Post by veremin » 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.

Markol
Enthusiast
Posts: 26
Liked: 2 times
Joined: Apr 20, 2012 12:12 pm
Full Name: Marko Lehto
Contact:

Re: Get average times from Veeam via PS

Post by Markol » 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...

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

Re: Get average times from Veeam via PS

Post by veremin » 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.

Markol
Enthusiast
Posts: 26
Liked: 2 times
Joined: Apr 20, 2012 12:12 pm
Full Name: Marko Lehto
Contact:

Re: Get average times from Veeam via PS

Post by Markol » Jan 15, 2014 2:56 pm

I'm not sure that I understand what you mean at the moment..

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

Re: Get average times from Veeam via PS

Post by veremin » 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.

Markol
Enthusiast
Posts: 26
Liked: 2 times
Joined: Apr 20, 2012 12:12 pm
Full Name: Marko Lehto
Contact:

Re: Get average times from Veeam via PS

Post by Markol » 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: Apr 20, 2012 12:12 pm
Full Name: Marko Lehto
Contact:

Re: Get average times from Veeam via PS

Post by Markol » 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: Apr 20, 2012 12:12 pm
Full Name: Marko Lehto
Contact:

Re: Get average times from Veeam via PS

Post by Markol » 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

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

Re: Get average times from Veeam via PS

Post by veremin » 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.

Markol
Enthusiast
Posts: 26
Liked: 2 times
Joined: Apr 20, 2012 12:12 pm
Full Name: Marko Lehto
Contact:

Re: Get average times from Veeam via PS

Post by Markol » 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

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

Re: Get average times from Veeam via PS

Post by veremin » Jan 16, 2014 10:52 am

Try to disable Strict mode and see whether it helps or not.

Code: Select all

Set-StrictMode -off
Thanks.

Markol
Enthusiast
Posts: 26
Liked: 2 times
Joined: Apr 20, 2012 12:12 pm
Full Name: Marko Lehto
Contact:

Re: Get average times from Veeam via PS

Post by Markol » Jan 16, 2014 11:09 am

Same thing,

But If I run it like this

Code: Select all

$interestingsess = $table | Sort StartTime -descending | select -first 2
 $interestingsess
    $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 2
    $points = $backup.GetStorages() | sort CreationTime -descending | Where-Object {$_.CreationTime -gt "2014-01-01"}
Then the
$interestingsess
prints out the 2, but after that errors.
  • At C:\Veeam-rapport.ps1:82 char:17
    + ($row. <<<< FileName = $point.FileName) -and ($row.CreationTime = $point.
    CreationTime)
    + CategoryInfo : InvalidOperation: (FileName:String) [], RuntimeExcepti
    on
    + FullyQualifiedErrorId : PropertyNotFound

    Property 'FileName' cannot be found on this object; make sure it exists and is settab
    le.
    At C:\Veeam-rapport.ps1:82 char:17
    + ($row. <<<< FileName = $point.FileName) -and ($row.CreationTime = $point.
    CreationTime)
    + CategoryInfo : InvalidOperation: (FileName:String) [], RuntimeExcepti
    on
    + FullyQualifiedErrorId : PropertyNotFound

Code: Select all

$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)    <------------------------- Row 82
        #Increment the $ic variable ( +1 )
        $ic+=1


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

Re: Get average times from Veeam via PS

Post by veremin » Jan 16, 2014 12:11 pm

Hmmm, it seems that $interestingsess sometimes gets assigned $Null value and the script doesn't proceed any further. Not sure, but you can try to check $interestingsess variable in order to exclude its $Null values:

Code: Select all

       $interestingsess = $table | Sort StartTime -descending | select -first 7
        $pkc = 1
        if ($interestingsess -ne $Null){
        $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
       }
       }
Thanks.

Markol
Enthusiast
Posts: 26
Liked: 2 times
Joined: Apr 20, 2012 12:12 pm
Full Name: Marko Lehto
Contact:

Re: Get average times from Veeam via PS

Post by Markol » Jan 16, 2014 12:56 pm

Changed the value to 1 in

Code: Select all

$interestingsess = $table | Sort StartTime -descending | select -first 1
1 of them was printed out. but after that
  • Index :
    JobName : Daily_B
    StartTime : 2013-12-25 19:30:00
    StopTime : 2013-12-25 19:40:42
    FileName :
    CreationTime :
    AvgSpeedMB : 845
    Duration : 00:10:42
    Result : Success


    True
  • Property 'FileName' cannot be found on this object; make sure it exists and is settab
    le.
    At C:\Veeam-rapport.ps1:87 char:17
    + ($row. <<<< FileName = $point.FileName) -and ($row.CreationTime = $point.
    CreationTime)
    + CategoryInfo : InvalidOperation: (FileName:String) [], RuntimeExcepti
    on
    + FullyQualifiedErrorId : PropertyNotFound

Markol
Enthusiast
Posts: 26
Liked: 2 times
Joined: Apr 20, 2012 12:12 pm
Full Name: Marko Lehto
Contact:

Re: Get average times from Veeam via PS

Post by Markol » Jan 16, 2014 1:40 pm 1 person likes this post

hmm, I think that it works now...

Using this code:

Code: Select all

 $interestingsess = $table | Where { ($_.StartTime) -gt (Get-Date 2014-01-01)}
 $interestingsess
 
 
    $pkc = 1
    #if ($interestingsess -ne $Null){
     #   Write-Output "KpyTo!"

    $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 4
    $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
        
       }
    }

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

Re: Get average times from Veeam via PS

Post by veremin » Jan 16, 2014 2:05 pm

So, generally speaking, you've just changed the way instances are selected. Instead of using "last 7" filter, you're utilizing "date" filter, right? It might happen that instances that contain $null value are older than "2014-01-01' and are not collected. Thus, there are no issue with undefined parameters.

Thanks.

Markol
Enthusiast
Posts: 26
Liked: 2 times
Joined: Apr 20, 2012 12:12 pm
Full Name: Marko Lehto
Contact:

Re: Get average times from Veeam via PS

Post by Markol » Jan 16, 2014 2:20 pm

v.Eremin wrote:So, generally speaking, you've just changed the way instances are selected. Instead of using "last 7" filter, you're utilizing "date" filter, right? Thanks.
Yes..

I got a bit confused due, the date was not correct, but when I started to think, the search is just for the Daily backups that run during weekedays :)

Thanks a lot for the help.
cheers

/Marko

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

Re: Get average times from Veeam via PS

Post by veremin » Jan 16, 2014 2:49 pm

Glad to hear that you nailed it. Let me know, if any additional help be needed. Thanks.

Markol
Enthusiast
Posts: 26
Liked: 2 times
Joined: Apr 20, 2012 12:12 pm
Full Name: Marko Lehto
Contact:

Re: Get average times from Veeam via PS

Post by Markol » Jan 17, 2014 10:22 am

Well might be one more thing.. But ok it's not about Veeam anymore... my mail script that I have, can I just put it at the bottom of the page and when the collection is done it will sen me the email?

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

Re: Get average times from Veeam via PS

Post by veremin » Jan 17, 2014 10:36 am

Yes, you can add it. Since, by default, lines in PS script are processed one by one, you will have exactly what you want to - once the session collection is finished, your mail script will be executed.

Thanks.

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests