PowerShell script exchange
Post Reply
RANR
Lurker
Posts: 2
Liked: 1 time
Joined: Feb 02, 2015 7:51 pm
Contact:

Script to export job details

Post by RANR »

I had some scripts that worked in Veeam 7 that compiled all of the information from our backup jobs into a single .htm file.

Unfortunately, none of those scripts seem to work now in Veeam 8. Does anyone have a script they could send me that works in 8? What I'd like is a detailed list of all of our jobs and how long it took each job to backup, over the course of a week.

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

Re: Script to export job details

Post by veremin »

By saying that script doesn't work you mean it lists nothing or throws errors? Can you provide a script itself, so that we can take a look at it?
RANR
Lurker
Posts: 2
Liked: 1 time
Joined: Feb 02, 2015 7:51 pm
Contact:

Re: Script to export job details

Post by RANR » 1 person likes this post

Thanks for your response.

This script used to work, now it just creates a blank HTML page. I did notc reate the script, I know nothing about Powershell, I found it on a forum. It used to work but no longer seems to work in Veeam 8.

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 -match ""}

foreach ($job in $Jobs) {
    $jobName = $job.Name
    $table = New-Object system.Data.DataTable "$table01"
	
	#region Setup table columns
    $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)
	#endregion

	#Grab all Backup Sessions on the server where their .JobId property is the same as the Get-VBRJob objects .Id property
    $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) 
            #Duration is a Timespan value, so I am formatting in here using 3 properties - HH,MM,SS
			$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 {
                    #Don't highlight if the backup session didn't fail.
					$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 {
		#for every object in $interestingsess (which has now been sorted by StartTime) assign the current value of $pkc to the .Index property. 1,2,3,4,5,6 etc...
		$_.Index = $pkc 
		#Increment $pkc, so the next foreach loop assigns a higher value to the next .Index property on the next row.
		$pkc+=1
	}
    
	#Now we are grabbing all the backup objects (same as viewing Backups in the Veeam B&R GUI Console
	$backup = Get-VBRBackup | ?{$_.JobId -eq $job.Id}
    $points = $backup.GetStorages() | sort CreationTime -descending | Select -First 7 #Find and assign the Veeam Backup files for each job we are going through and sort them in descending order. Select the specified amount.
    #Increment variable is set to 1 to start off
	$ic = 1 
    ForEach ($point in $points) {
       #Match the $ic (Increment variable) up with the Index number we kept earlier, and assign $table to $rows where they are the same. This happens for each object 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: 20413
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Script to export job details

Post by veremin »

Did you execute this script manually or via Windows Scheduler, for instance? Can you try to run it under administrator account?

By the way, I've just run it in my lab, and it's worked without any issues creating a corresponding htm file that contains required information.

Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests