forked from VeeamHub/powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBackupReport.ps1
71 lines (62 loc) · 2.34 KB
/
BackupReport.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<#
.SYNOPSIS
Generates html report on Backups and Backup Copies.
.SYNTAX
Get-BackupReport -Path <string[]> [-Backup] [-BackupCopy]
.PARAMETERS
-path <string[]>
-Backup <switch>
-BackupCopy <switch>
#>
add-pssnapin -name VeeamPSSnapin
connect-vbrserver -server localhost
$styleHtml = @"
<style>
TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}
TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black; background-color: #6495ED;}
TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}
</style>
"@
function get-backupreport {
[cmdletbinding(defaultparametersetname = 'Path')]
param (
[parameter(
mandatory,
parametersetname = 'Path',
valuefrompipeline,
valuefrompipelinebypropertyname
)]
[validatenotnullorempty()]
[string[]]$Path,
[switch]$Backup,
[switch]$BackupCopy
)
if ($Backup) {
$includeJobs = "^Backup$"
} elseif ($BackupCopy) {
$includeJobs = "^BackupSync$"
} else {
$includeJobs = "^Backup$|^BackupSync$"
}
$sessions = Get-VBRBackupSession | ?{$_.JobType -match $includeJobs}
$taskSessions = $sessions.GetTaskSessions() | Group-Object -Property Name -AsHashTable
$sessionInfo = @()
$importPath = get-content -LiteralPath $Path
$sessionInfo = foreach ($import in $importPath) {
$taskSessions.$import | Select-Object @{n='VM Name';e={$_.Name}}, @{n='Result';e={$_.Status}}, @{n='Job Name';e={$_.JobName}}, @{n='Job Type';e={$_.JobSess.JobType}}, @{n='Start time';e={$_.Progress.StartTimeLocal}}, @{n='End time';e={$_.Progress.StopTimeLocal}}
}
$sessionInfo = $sessionInfo | Sort-Object "VM Name", "Job Type", "Job Name", "Start Time"
$exportDir = test-path -path 'C:\Temp'
$currentDate = (get-date).tostring('MM-dd-yyyy')
$exportTo = 'C:\Temp\BackupReport-' + $currentDate + '.html'
if (!$exportDir)
{
new-item -ItemType directory -Path 'C:\Temp'
$sessionInfo | convertto-html -Head $styleHtml | out-file -filepath $exportTo -Append
write-host 'The report was saved to C:\Temp\BackupReport.html'-ForegroundColor Green
}
elseif ($exportDir){
write-host 'The report was saved to C:\Temp\BackupReport.html'-ForegroundColor Green
$sessionInfo | convertto-html -Head $styleHtml | out-file -filepath $exportTo -Append
}
}