PowerShell script exchange
Post Reply
Andreswa777
Lurker
Posts: 2
Liked: never
Joined: Jan 07, 2019 9:53 am
Full Name: Andres
Contact:

Daily report for Replications

Post by Andreswa777 »

I am trying to make a simple summary report that will run daily (00:00) that will list all the Replication Jobs Only with their Status (Success/Failure), Time Start, Time Complete and Total Size in GB.
This is needed for our Audits - as there is numerous Replication jobs, we don't print them for the daily checklist but during Audit, we need to go through a heap of emails to select and print selected date.
Having a single report for a whole day in .html or .csv/xlsx will be a lot better.

I got this going so far, where I pull a few details from all Replication jobs.
It currently list all jobs, their status, next scheduled run etc but only for the current session/job.

I need it to be able to go back into the history of the days Replication as it replicates 2-4 times a day.

Code: Select all

param(
    [String]$outfile="C:\Reports\ReplicaReport.$((Get-Date).ToString('dd-MM-yyyy_HH-mm')).html",
    [String]$Server="localhost"
)

if ((Get-PSSnapin -Name VeeamPSSNapin -ErrorAction SilentlyContinue) -eq $null)
{
    Add-PSSnapin VeeamPSSNapin
}

$head = @"
<style>
th {background-color: #00aff0} 
table {border-collapse: collapse} 
table, th, td {
border: 1px solid black;
padding: 5px
} 
th {color: white} 
body {font-family: sans-serif} 
</style>
"@

$results = @()

######
## Connect to server
######

if ($Server -eq $null) {
    Connect-VBRServer -Server $server 
} else {
    Disconnect-VBRServer
Connect-VBRServer -Server $server 
}

# Get Replication Jobs
$JobNames = Get-VBRJob | Where-Object {$_.JobType -eq "Replica"}

foreach ($JobName in $JobNames) {
    $Job = Get-VBRJob -name $JobName.Name
    $LastSession = $Job.FindLastSession()
    $Name = $Job.Name
    $Status = $LastSession.State
    $Progress = "$($LastSession.BaseProgress)%"
    $Test = $job.ScheduleOptions.get_NextRun()
    

    $results += New-Object PSObject -Property @{JobName = $Name; Status = $Status; Progress = $Progress; Test = $Test}
} 


$results |
Select JobName, Status, Progress, New |
sort @{expression="Status";Descending=$false},@{expression="JobName";Ascending=$true} |
ConvertTo-Html -body "<H2>Veeam Replication Job </H2> <p>The following report was run on $(get-date).</p>" -PreContent $head -Title "Veeam OffSite Backups Information" | 
    foreach {
        $PSItem -replace "<td>Working</td>", "<td style='background-color:green; color: white'>Running</td>" -replace "<td>Idle</td>", "<td style='background-color:orange; color: white'>Idle</td>" -replace "<td>Stopped</td>", "<td style='background-color:red; color: white'>Stopped</td>"
    } | Out-File $outfile
jhoughes
Veeam Vanguard
Posts: 282
Liked: 113 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Castle Rock, CO
Contact:

Re: Daily report for Replications

Post by jhoughes »

Shawn's report should cover everything that you're looking for, including reporting for historical sessions. https://blog.smasterson.com/2017/12/22/ ... ort-9-5-3/

You could also look through the code to see how he's performing the same tasks and just borrow some snippets of the original code.
Husband, Father, Solutions Architect, Geek | @DenverVMUG & @DenverPSUG leader | International Speaker | Veeam Vanguard | vExpert (PRO) | Cisco Champion
Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests