Get average times from Veeam via PS

PowerShell script exchange

Re: Get average times from Veeam via PS

Veeam Logoby v.Eremin » Thu 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.
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 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

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 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.
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 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: 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 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
       
       }
    }
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 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.
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 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
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 2:49 pm

Glad to hear that you nailed it. Let me know, if any additional help be needed. 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 » Fri 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?
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 » Fri 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.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Previous

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 3 guests