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