powershell veeam report with gui

PowerShell script exchange

powershell veeam report with gui

Veeam Logoby larry » Fri Mar 03, 2017 10:25 pm 3 people like this post

I needed an html report from the last ten sessions of all jobs and wanted to play with powershell gui so here is a job picker, date picker and output html to form. Some code is from myveeamreport. The html preview is mine.
as you run each it creates a html report in c:\temp so you will need that directory or change code. must run on the veeam server as I don't do a connect. Only does backup jobs but you could create a pull down for any job type. code below


Code: Select all

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 

Add-PSSnapin "VeeamPSSnapIn" -ErrorAction SilentlyContinue

$joblsit = (Get-VBRJob | ? {$_.JobType -eq "Backup"} | sort Name)

$Form = New-Object System.Windows.Forms.Form   
$Form.Size = New-Object System.Drawing.Size(1650,1000)

############################################## Start functions
function CombineHTML  {

# Combine HTML Output
$htmlOutput = $headerObj + $bodyTop + $bodySummaryBK + $bodyJobsBk + $bodytapeBk + $bodySummaryEp + $bodyMissing + $bodySuccess  + $bodyRunningBk + $bodySessWFBk +
$bodySessSuccBk + $bodyRestoRunVM + $bodyRestoreVM + $bodyJobsEp + $bodyRunningEp + $bodySessWFEp + $bodySessSuccEp + $bodyRepo + $bodyProxy +
$bodyReplica + $bodyServices + $bodyLicense + $footerObj

# Add color to output depending on results
#Green
$htmlOutput = $htmlOutput.Replace("<td>Running<","<td style=""background-color: Green;color: White;"">Running<")
$htmlOutput = $htmlOutput.Replace("<td>OK<","<td style=""background-color: Green;color: White;"">OK<")
$htmlOutput = $htmlOutput.Replace("<td>Alive<","<td style=""background-color: Green;color: White;"">Alive<")
$htmlOutput = $htmlOutput.Replace("<td>Success<","<td style=""background-color: Green;color: White;"">Success<")
#Yellow
$htmlOutput = $htmlOutput.Replace("<td>Warning<","<td style=""background-color: Yellow;"">Warning<")
#Red
$htmlOutput = $htmlOutput.Replace("<td>Not Running<","<td style=""background-color: Red;color: White;"">Not Running<")
$htmlOutput = $htmlOutput.Replace("<td>Failed<","<td style=""background-color: Red;color: White;"">Failed<")
$htmlOutput = $htmlOutput.Replace("<td>Critical<","<td style=""background-color: Red;color: White;"">Critical<")
$htmlOutput = $htmlOutput.Replace("<td>Dead<","<td style=""background-color: Red;color: White;"">Dead<")
#$VeeamJob=$DropDownBox.SelectedItem.ToString()
#$reportfilename = "c:\temp\$VeeamJob.html"
$htmlOutput >$reportfilename
}
function procInfo {
$VeeamJob=$DropDownBox.SelectedItem.ToString() #populate the var with the value you selected
$Button.Enabled = $false
$Button.BackColor = 'white'
$Button.text = "Working"
$Button.Refresh()
$fromdate = $calendar.SelectionStart# Gather all Backup sessions within timeframe
$todate = $calendar2.SelectionStart# Gather all Backup sessions within timeframe

$HourstoCheck = 100000

$tempArry =@()
$tempArry = Get-VBRBackupSession| ?{$_.CreationTime -ge ($fromdate).AddDays(0) -AND $_.CreationTime -le ($todate).AddDays(1)}
$allSesh = $allSesh+ $tempArry

$tempArry =@()
$tempArry = @(Get-VBRJob | ? {$_.JobType -eq "Backup"})
$allJobsBk = $allJobsBk + $tempArry
$fromdate = $calendar.SelectionStart# Gather all Backup sessions within timeframe

$seshListBk = @($allSesh | ?{($_.CreationTime -ge $fromdate.AddHours(-$HourstoCheck)) -and $_.JobType -eq "Backup"  })

# Get Backup session information
$totalxferBk = 0
$totalReadBk = 0
$seshListBk | %{$totalxferBk += $([Math]::Round([Decimal]$_.Progress.TransferedSize/1GB, 2))}
$seshListBk | %{$totalReadBk += $([Math]::Round([Decimal]$_.Progress.ReadSize/1GB, 2))}
$tempSeshListBk = $seshListBk
$seshListBk = @()
Foreach($job in (Get-VBRJob | ? {$_.JobType -eq "Backup" -and $_.Name -eq $VeeamJob  })) {
$seshListBk += $TempSeshListBk | ?{$_.Jobname -eq $job.name} | Sort-Object CreationTime -Descending | Select-Object -First $numberBox1.Value
}

$successSessionsBk = @($seshListBk | ?{$_.Result -eq "Success"})
$warningSessionsBk = @($seshListBk | ?{$_.Result -eq "Warning"})
$failsSessionsBk = @($seshListBk | ?{$_.Result -eq "Failed"})
$runningSessionsBk = @($allSesh | ?{$_.State -eq "Working" -and $_.JobType -eq "Backup"})
$failedSessionsBk = @($seshListBk | ?{($_.Result -eq "Failed") -and ($_.WillBeRetried -ne "True")})

$All = @($seshListBk)

$headerSucc = "Backup Jobs"

$bodySessSuccBk = $All | Sort Name, Creationtime | Select @{Name="Job Name"; Expression = {$_.Name}},
                @{Name="Start Time"; Expression = {$_.CreationTime}},
                @{Name="Stop Time"; Expression = {$_.EndTime}},
@{Name="Duration (Mins)"; Expression = {[Math]::Round($_.WorkDetails.WorkDuration.TotalMinutes,2)}},
@{Name="Avg Speed (MB/s)"; Expression = {[Math]::Round($_.Info.Progress.AvgSpeed/1MB,2)}},
@{Name="Total (GB)"; Expression = {[Math]::Round($_.Info.Progress.ProcessedSize/1GB,2)}},
@{Name="Processed (GB)"; Expression = {[Math]::Round($_.Info.Progress.ProcessedUsedSize/1GB,2)}},
@{Name="Data Read (GB)"; Expression = {[Math]::Round($_.Info.Progress.ReadSize/1GB,2)}},
@{Name="Transferred (GB)"; Expression = {[Math]::Round($_.Info.Progress.TransferedSize/1GB,2)}},
Result  | ConvertTo-HTML -Fragment
               $bodySessSuccBk = $subHead01 + $headerSucc + $subHead02 + $bodySessSuccBk


$reportfilename = "c:\temp\$VeeamJob.html"
CombineHTML
#$bodySessSuccBk >$reportfilename
$browser.navigate("file://$reportfilename")
#$bodySessSuccBk >$reportfilename
$Label.Text = "HTML Report file name: $reportfilename";

$Button.Text = "Create Report"
$Button.BackColor = 'gray'

#$Button.Enabled = $true

                     } #end procInfo

############################################## end functions
###start heade
$rptTitle = "Veeam Job Report"
$rptWidth = 1200

# HTML Stuff
$headerObj = @"
<html>
        <head>
                <title>$rptTitle</title>
                <style> 
                        body {font-family: Tahoma; background-color:#fff;}
table {font-family: Tahoma;width: $($rptWidth)px;font-size: 12px;border-collapse:collapse;}
                        <!-- table tr:nth-child(odd) td {background: #e2e2e2;} -->
th {background-color: #cccc99;border: 1px solid #a7a9ac;border-bottom: none;}
                        td {background-color: #ffffff;border: 1px solid #a7a9ac;padding: 2px 3px 2px 3px;vertical-align: top;}
                </style>
        </head>
"@
 
$bodyTop = @"
        <body>
<center>
                <table cellspacing="0" cellpadding="0">
                        <tr>
                                <td style="width: 80%;height: 45px;border: none;background-color: #003366;color: White;font-size: 24px;vertical-align: bottom;padding: 0px 0px 0px 15px;">$rptTitle</td>
                                <td style="width: 20%;height: 45px;border: none;background-color: #003366;color: White;font-size: 12px;vertical-align:text-top;text-align:right;padding: 2px 3px 2px 3px;"></td>
                        </tr>
<tr>
                                <td style="width: 80%;height: 35px;border: none;background-color: #003366;color: White;font-size: 10px;vertical-align: bottom;padding: 0px 0px 2px 3px;">Report generated at $(Get-Date -format g) on $((gc env:computername).ToLower())</td>
                                <td style="width: 20%;height: 35px;border: none;background-color: #003366;color: White;font-size: 10px;vertical-align:bottom;text-align:right;padding: 2px 3px 2px 3px;"></td>
                        </tr>
                </table>
"@
 
$subHead01 = @"
                <table>
                        <tr>
                                <td style="height: 35px;background-color: #eeeeee;color: #003366;font-size: 16px;font-weight: bold;vertical-align: middle;padding: 5px 0 0 15px;border-top: 1px solid #cccc99;border-bottom: none;">
"@

$subHead01err = @"
                <table>
                        <tr>
                                <td style="height: 35px;background-color: #FF0000;color: #003366;font-size: 16px;font-weight: bold;vertical-align: middle;padding: 5px 0 0 15px;border-top: 1px solid #cccc99;border-bottom: none;">
"@

$subHead02 = @"
                                </td>
                        </tr>
                </table>
"@

$footerObj = @"
</center>
</body>
</html>
"@



############################################## Start drop down boxes

$DropDownBox = New-Object System.Windows.Forms.ComboBox
$DropDownBox.Location = New-Object System.Drawing.Size(20,50)
$DropDownBox.Size = New-Object System.Drawing.Size(380,20)
$DropDownBox.DropDownHeight = 400
$DropDownBox.text = "Select Job"

write-host "ok1"

foreach ($job in $joblsit) {
                      $DropDownBox.items.add($job.Name)
                              } #end fo
$DropDownBox.add_SelectedIndexChanged({$Button.Enabled = $true
 $Button.BackColor = 'lightgreen'})
$Form.Controls.Add($DropDownBox)
############################################## end drop down boxes
write-host "ok2"
####number box
$Labe2 = New-Object System.Windows.Forms.Label
$Labe2.Size = New-Object Drawing.Size(70,20)
$Labe2.Location = New-Object Drawing.Size(1000,12)
$Labe2.Text = "Num Of Jobs"
$Labe2.AutoSize = $True

$Form.Controls.Add($Labe2)
$numberBox1 = New-Object System.Windows.Forms.NumericUpDown
$numberBox1.Size = New-Object Drawing.Size(90,20)
$numberBox1.Location = New-Object Drawing.Size(1000,50)
$numberBox1.Maximum = 9999;
$Form.Controls.Add($numberBox1)
$numberBox1.Value = 10
#####################browser
$browser = new-object System.Windows.Forms.WebBrowser
$browser.Size = New-Object System.Drawing.Size(1250,770)
$browser.Location = New-Object System.Drawing.Size(10,150)
#$browser.navigate("sharepoint page url")
$Form.Controls.Add($browser)

############################################## Start text fields

############################################## end text fields
#####start checkbox
$objTypeCheckbox = New-Object System.Windows.Forms.Checkbox
 $objTypeCheckbox.Location = New-Object System.Drawing.Size(1300,60)
 $objTypeCheckbox.Size = New-Object System.Drawing.Size(500,30)
 $objTypeCheckbox.Text = "Use Dates"
 $Form.Controls.Add($objTypeCheckbox)
$objTypeCheckbox.Add_CheckStateChanged({
    if ($objTypeCheckbox.checked)
     {$numberBox1.Value = 9999
      $calendar.SelectionStart =Get-Date
     }else
     {$numberBox1.Value = 10
     $calendar.SelectionStart = "12/31/2010"

    }
 })

 ###############
#### start from date
$Labe3 = New-Object System.Windows.Forms.Label
$Labe3.Size = New-Object Drawing.Size(70,20)
$Labe3.Location = New-Object Drawing.Size(1280,120)
$Labe3.Text = "From Date"
$Labe3.AutoSize = $True
$Form.Controls.Add($Labe3)
$calendar = New-Object System.Windows.Forms.MonthCalendar
$calendar.Location = New-Object System.Drawing.Size(1280,150)
$calendar.Size = New-Object System.Drawing.Size(120,60) 
$calendar.ShowTodayCircle = $False
$calendar.MaxSelectionCount = 1
$calendar.SelectionStart = "12/31/2010"
$form.Controls.Add($calendar)


#### start to
$Labe4 = New-Object System.Windows.Forms.Label
$Labe4.Size = New-Object Drawing.Size(70,20)
$Labe4.Location = New-Object Drawing.Size(1280,500)
$Labe4.Text = "To Date"
$Labe4.AutoSize = $True
$Form.Controls.Add($Labe4)
$calendar2 = New-Object System.Windows.Forms.MonthCalendar
$calendar2.Location = New-Object System.Drawing.Size(1280,530)
$calendar2.Size = New-Object System.Drawing.Size(120,60) 
$calendar2.ShowTodayCircle = $False
$calendar2.MaxSelectionCount = 1
$form.Controls.Add($calendar2)


############################################## Start buttons

$Button = New-Object System.Windows.Forms.Button
$Button.Location = New-Object System.Drawing.Size(700,30)
$Button.Size = New-Object System.Drawing.Size(110,80)
$Button.Text = "Create Report"
$Button.Add_Click({procInfo})
$Button.Enabled = $false
$Form.Controls.Add($Button)
$Button.Enabled = $false
$Button.BackColor = 'gray'
############################################## end buttons
######### start label

$Font = New-Object System.Drawing.Font("Times New Roman",18,[System.Drawing.FontStyle]::Italic)
# Font styles are: Regular, Bold, Italic, Underline, Strikeout
$Form.Font = $Font
$Label = New-Object System.Windows.Forms.Label
$Label.Text = "HTML Report file name:"
$Label.AutoSize = $True
$Form.Controls.Add($Label)
#######################
$Form.BackColor = 'lightblue'
$Form.Add_Shown({$Form.Activate()})
[void] $Form.ShowDialog()
larry
Expert
 
Posts: 383
Liked: 90 times
Joined: Wed Mar 24, 2010 5:47 pm
Full Name: Larry Walker

Re: powershell veeam report with gui

Veeam Logoby Vitaliy S. » Sun Mar 05, 2017 8:30 pm

Hi Larry,

Thanks for sharing, nicely done! BTW, all similar reports are available in Veeam ONE today > Veeam Backup Monitoring

Thanks!
Vitaliy S.
Veeam Software
 
Posts: 19942
Liked: 1144 times
Joined: Mon Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 2 guests