The code iam trying to run is :
$scriptDirectory = Split-Path -Parent $MyInvocation.MyCommand.Path
$agentJobListFile = Join-Path -Path $scriptDirectory -ChildPath "AgentJobsList.txt"
$csvFilePath = Join-Path -Path $scriptDirectory -ChildPath "Veeamagent.csv"
function Check-FileExists {
param ([string]$filePath)
if (-not (Test-Path -Path $filePath)) {
Write-Error "❌ The required file '$filePath' does not exist."
exit 1
} else {
Write-Host "✅ Found input file: $filePath"
}
}
Check-FileExists -filePath $agentJobListFile
$allAgentJobData = @()
$agentJobNames = Get-Content -Path $agentJobListFile
Write-Host "✅ Loaded $(($agentJobNames).Count) agent job names from AgentJobsList.txt"
foreach ($agentJobName in $agentJobNames) {
Write-Host "`n🚀 Processing agent job: $agentJobName"
$job = Get-VBRComputerBackupJob -Name $agentJobName -ErrorAction SilentlyContinue
if ($null -eq $job) {
Write-Warning "⚠️ Skipping: Job '$agentJobName' not found."
continue
}
# Get the last session for this job only (memory-safe)
$session = Get-VBRBackupSession -Job $job | Sort-Object CreationTime -Descending | Select-Object -First 1
if ($null -eq $session) {
Write-Warning "⚠️ No session found for job: $agentJobName"
continue
}
Write-Host "📦 Last session: $($session.CreationTime)"
$tasks = Get-VBRTaskSession -Session $session
Write-Host "🔧 Task count: $($tasks.Count)"
foreach ($task in $tasks) {
$jobData = [PSCustomObject]@{
JobName = $job.Name
Computer = $task.Name
StartTime = $task.Progress.StartTime
EndTime = $task.Progress.StopTime
Duration = if ($task.Progress.StopTime -and $task.Progress.StartTime) {
($task.Progress.StopTime - $task.Progress.StartTime).ToString()
} else { "N/A" }
Status = $task.Status
Result = $task.Result
BackupSizeGB = if ($task.Progress.ProcessedSize) {
"{0:N2}" -f ($task.Progress.ProcessedSize / 1GB)
} else { "0.00" }
}
$allAgentJobData += $jobData
}
}
if ($allAgentJobData.Count -gt 0) {
$allAgentJobData | Export-Csv -Path $csvFilePath -NoTypeInformation -Encoding UTF8
Write-Host "`n✅ Agent job data exported to: $csvFilePath"
} else {
Write-Host "`n⚠️ No agent job data was found to export."
}
Error I got :
Method invocation failed because [Veeam.Backup.PowerShell.Infos.VBRComputerBackupJob] does not contain a method named '
GetLastSession'.
At C:\Users\T1SV132301\Documents\Daily_Report_Generation\Daily_Report_Generation\Veeamagent.ps1:38 char:5