Code: Select all
if ($job -eq $null) {
Write-Host "The job named '$jobName' does not exist"
}
else
{
# Get information about the virtual machines in the job
$vmsInJob = $job.GetObjectsInJob()
if ($vmsInJob.Count -gt 0) {
Write-Host "VMs in job '$jobName':"
$vmsInJob | ForEach-Object {
$vmName = $_.Name
# Get the backup sessions for a given virtual machine
$backupSessionsForVM = Get-VBRBackupSession
# Specify the time range for November
$startDate = Get-Date -Day 1 -Month 11 -Year 2023 -Hour 0 -Minute 0 -Second 0
$endDate = Get-Date -Day 1 -Month 12 -Year 2023 -Hour 0 -Minute 0 -Second 0
# Filter backup sessions for a given VM based on time range and "Success" status
$successfulBackupsForVM = $backupSessionsForVM | Where-Object
{
$_.EndTime -ge $startDate -and $_.EndTime -lt $endDate -and $_.Result -eq "Success" -and $_.IsFullMode -eq $True
}
| Sort-Object EndTime -Descending
# Display the number of successful full backups for a given virtual machine
Write-Host "Liczba udanych pełnych backupów dla VM '$vmName' w zadaniu '$jobName' w grudniu: $($successfulBackupsForVM.Count)"
# Display the dates of successful full backups for a given VM
$successfulBackupsForVM | ForEach-Object {
Write-Host "Data udanego pełnego backupu dla VM '$vmName': $($_.EndTime)"
}
}
}
else
{
Write-Host "No information about the VMs in the task."
}
}
Code: Select all
VMs in 'Backup Job MyJob' job:
Number of successful full backups for VM '[job] VMname' in 'Backup Job MyJob' task in November: 265
Date of successful full backups for VM '[job] VMname': 11/13/2023 12:29:21
Date of successful full backups for VM '[job] VMname': 11/13/2023 10:19:31
Date of successful full backups for VM '[job] VMname': 11/13/2023 08:09:43