cls
Write-Host "VEEAM GUI - single Tape Job sessions.1.0" -BackgroundColor DarkRed -ForegroundColor Yellow
Write-Host "Wait...Wait...Wait..."
# Importing necessary .NET Assembly
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
# Main Form
$MainForm = New-Object System.Windows.Forms.Form
$MainForm.Text = 'Veeam Tape Backup Job'
$MainForm.Size = New-Object System.Drawing.Size(350, 400)
$MainForm.StartPosition = 'CenterScreen'
$MainForm.TopMost = $true
# Prepare for CSV Export
$OutputPath = 'C:\Veeam-Tape-Logs'
if (!(Test-Path -Path $OutputPath -PathType Container)) {
$null = New-Item -ItemType Directory -Path $OutputPath
}
# Fetch all tape jobs upfront
$TapeJobs = Get-VBRTapeJob
# GUI elements
# Jobs ListBox
$ListBoxJobs = New-Object System.Windows.Forms.ListBox
$ListBoxJobs.Location = New-Object System.Drawing.Point(10, 10)
$ListBoxJobs.Size = New-Object System.Drawing.Size(300, 100)
# Checkbox for OGV output
$CheckboxOgvOutput = New-Object System.Windows.Forms.CheckBox
$CheckboxOgvOutput.Location = New-Object System.Drawing.Point(10, 130)
$CheckboxOgvOutput.Text = 'Enable OGV Output'
$CheckboxOgvOutput.AutoSize = $true
# Checkbox for sending only Error output
$CheckboxOnlyError = New-Object System.Windows.Forms.CheckBox
$CheckboxOnlyError.Location = New-Object System.Drawing.Point(10, 160)
$CheckboxOnlyError.Text = 'Only send Error output'
$CheckboxOnlyError.AutoSize = $true
# Email Label
$LabelEmail = New-Object System.Windows.Forms.Label
$LabelEmail.Text = 'Email'
$LabelEmail.AutoSize = $true
$LabelEmail.Location = New-Object System.Drawing.Point(10, 200)
# Email TextBox
$TextBoxEmail = New-Object System.Windows.Forms.TextBox
$TextBoxEmail.Location = New-Object System.Drawing.Point(10, 230)
$TextBoxEmail.Width = 300
$TextBoxEmail.BackColor = 'LightGray'
# Checkbox to include other recipients
$CheckboxIncludeOthers = New-Object System.Windows.Forms.CheckBox
$CheckboxIncludeOthers.Location = New-Object System.Drawing.Point(10, 260)
$CheckboxIncludeOthers.Text = 'Include other recipients'
$CheckboxIncludeOthers.AutoSize = $true
# Export Button
$ButtonExport = New-Object System.Windows.Forms.Button
$ButtonExport.Location = New-Object System.Drawing.Point(10, 310)
$ButtonExport.Size = New-Object System.Drawing.Size(100, 30)
$ButtonExport.Text = 'Export CSV'
$ButtonExport.BackColor = 'Blue'
$ButtonExport.ForeColor = 'White'
# Send Mail Button
$ButtonSendMail = New-Object System.Windows.Forms.Button
$ButtonSendMail.Location = New-Object System.Drawing.Point(120, 310)
$ButtonSendMail.Size = New-Object System.Drawing.Size(100, 30)
$ButtonSendMail.Text = 'Send Mail'
$ButtonSendMail.BackColor = 'Blue'
$ButtonSendMail.ForeColor = 'White'
# Open CSV Folder Button
$ButtonOpenFolder = New-Object System.Windows.Forms.Button
$ButtonOpenFolder.Location = New-Object System.Drawing.Point(230, 310)
$ButtonOpenFolder.Size = New-Object System.Drawing.Size(100, 30)
$ButtonOpenFolder.Text = 'Open Folder'
$ButtonOpenFolder.BackColor = 'Blue'
$ButtonOpenFolder.ForeColor = 'White'
# Label for authoring information
$LabelAuthoring = New-Object System.Windows.Forms.Label
$LabelAuthoring.Text = "Created by Vladisla2000 and ChatGPT"
$LabelAuthoring.AutoSize = $true
$LabelAuthoring.Location = New-Object System.Drawing.Point(10, 360)
# Add controls to MainForm
$MainForm.Controls.AddRange(@($ListBoxJobs, $CheckboxOgvOutput, $CheckboxOnlyError, $LabelEmail, $TextBoxEmail, $CheckboxIncludeOthers, $ButtonExport, $ButtonSendMail, $ButtonOpenFolder, $LabelAuthoring))
# Fill the ListBox with job names when the MainForm is loaded
$MainForm.Add_Load({
foreach ($Job in $TapeJobs) {
$ListBoxJobs.Items.Add($Job.Name)
}
})
# Define the action for the button click to export CSV
$ButtonExport_Click = {
$SelectedJob = $ListBoxJobs.SelectedItem
if ($null -ne $SelectedJob) {
# Get job information
$Job = $TapeJobs | Where-Object { $_.Name -eq $SelectedJob }
# Define date one year ago
$OneYearAgo = (Get-Date).AddYears(-1)
# Filter backup sessions for the selected job from the last year
$JobSessions = Get-VBRTapeBackupSession -Job $Job | Where-Object { $_.CreationTime -gt $OneYearAgo }
# Prepare CSV Export
$CsvExport = $JobSessions | ForEach-Object {
[PSCustomObject]@{
'JobName' = $Job.Name
'SessionName' = $_.Name
'Result' = $_.Result
'CreationTime' = $_.CreationTime
}
}
# Define the output filename to include date and hour
$OutputFileName = "$($Job.Name)_$(Get-Date -Format "yyyyMMdd_HHmm").csv"
# Export to CSV
$CsvExport | Export-Csv -Path "$OutputPath\$OutputFileName" -NoTypeInformation
# If CheckboxOgvOutput is checked, output the CSV content to Out-GridView
if ($CheckboxOgvOutput.Checked) {
$CsvExport | Out-GridView
}
# If CheckboxOnlyError is checked, filter the jobs with 'Failed' status
if ($CheckboxOnlyError.Checked) {
$CsvExport = $CsvExport | Where-Object { $_.Result -eq 'Failed' }
}
# Show Export Completed message
[System.Windows.Forms.MessageBox]::Show("Export completed", "Information")
} else {
[System.Windows.Forms.MessageBox]::Show("Please select a job from the list", "Information")
}
}
$ButtonExport.Add_Click($ButtonExport_Click)
# Define the action for the button click to send mail
$ButtonSendMail_Click = {
# Send Email
if ($TextBoxEmail.Text) {
$SmtpServer = "your.smtp.server"
$From = vladsp@gamaf.co.il
$To = vladsp@gamaf.co.il
$Subject = "Veeam Tape Backup Job Status"
$Body = "Please find the attached CSV file for Veeam Tape Backup Job Status."
$Attachment = "$OutputPath\$($ListBoxJobs.SelectedItem)_$(Get-Date -Format "yyyyMMdd_HHmm").csv"
if ($CheckboxIncludeOthers.Checked) {
$To += ",additional.email@domain.com"
}
Send-MailMessage -From $From -To $To -SmtpServer $SmtpServer -Subject $Subject -Body $Body -Attachments $Attachment
# Show Email Sent message
[System.Windows.Forms.MessageBox]::Show("Email sent", "Information")
} else {
[System.Windows.Forms.MessageBox]::Show("Please enter an email address", "Warning")
}
}
$ButtonSendMail.Add_Click($ButtonSendMail_Click)
# Define the action for the button click to open the CSV folder
$ButtonOpenFolder_Click = {
# Open the folder in Explorer
Invoke-Item -Path $OutputPath
}
$ButtonOpenFolder.Add_Click($ButtonOpenFolder_Click)
# Show MainForm
$MainForm.ShowDialog()
# Dispose MainForm after use
$MainForm.Dispose()
Комментариев нет:
Отправить комментарий