I am running a powershell script to gather information about tape jobs on my server. It works perfectly for backup to tape jobs, but I can't seem to get the information I need for files to tape jobs. Its like the normal functions don't work for those jobs. My script crawls through all the Tape jobs on the server and gets the last status and run time for the job, but when it hits a files-to-tape job the script hangs and I have had to just exclude those jobs. Here is what I have currently. How would I go about getting last status and completion time for files-to-tape as I have from backups-to-tape below:
# Loop through each tape job
foreach ($TapeJob in $TapeJobs) {
Write-Host "Processing tape job: $($TapeJob.Name) (Type: $($TapeJob.Type))" -ForegroundColor Gray
# Skip "Files to Tape" jobs (since we can't retrieve their session history)
if ($TapeJob.Type -eq "FileToTape") {
$JobReport += "⚠️ Skipping 'Files to Tape' job '$($TapeJob.Name)' (No valid cmdlet to check last run)."
continue
}
$LastSession = $null # Reset for each job
try {
# Use Get-VBRTapeBackupSession for "Backup to Tape" jobs
$LastSession = Get-VBRTapeBackupSession -Job $TapeJob |
Where-Object { $_.Result -eq "Success" } |
Sort-Object EndTime -Descending |
Select-Object -First 1
}
catch {
Write-Host "⚠️ ERROR: Failed to retrieve session for '$($TapeJob.Name)'. Skipping..." -ForegroundColor Yellow
continue
}
# Determine if it ran successfully in the past 24 hours
if ($LastSession) {
$LastRunTime = $LastSession.EndTime
$TimeDiff = ($CurrentTime - $LastRunTime).TotalHours
if ($LastRunTime -lt $TimeThreshold) {
$JobReport += "❌ ALERT: Tape job '$($TapeJob.Name)' has NOT run successfully in the last 24 hours! (Last success: $($LastRunTime.ToString('yyyy-MM-dd HH:mm:ss')))"
$MissingJobs += $TapeJob.Name
} else {
$JobReport += "✅ Tape job '$($TapeJob.Name)' ran successfully at $($LastRunTime.ToString('yyyy-MM-dd HH:mm:ss'))"
}
} else {
$JobReport += "⚠️ WARNING: Tape job '$($TapeJob.Name)' has NEVER had a successful run!"
$MissingJobs += $TapeJob.Name
}
}
I would check the File to Tape (FTT) jobs one by one through your logic, as I think it's related to your environment. I ran your script quick in my lab and it worked without issue:
PS C:\Users\david.LAB> $JobReport WARNING: Tape job 'TP-nano-to-tape' has NEVER had a successful run! WARNING: Tape job 'F2T-object-wasabi' has NEVER had a successful run! WARNING: Tape job 'TP-BJ-Nano' has NEVER had a successful run! Tape job 'TP-FK-GFS' ran successfully at 2025-03-12 22:45:42 Tape job 'Backup to Tape Job 5' ran successfully at 2025-03-13 00:07:34 Tape job 'TP-F2T-localdisk' ran successfully at 2025-03-18 18:00:56 Tape job 'TP-GFS-nano' ran successfully at 2025-03-18 00:03:41 Tape job 'F2T-always-full' ran successfully at 2025-03-19 08:54:59
PS C:\Users\david.LAB> $tJob = Get-VBRTapeJob -Name "F2T-always-full"
PS C:\Users\david.LAB> $tSess = Get-VBRTapeBackupSession -Job $tJob | Sort -Property CreationTime -Descending | Select -First 1
PS C:\Users\david.LAB> $tSess.EndTime
Mittwoch, 19. März 2025 08:54:59
So my guess is something is happening when trying to retrieve the session data for one of the File to Tape jobs, but cannot reproduce it in my lab.
Also just a hint, but on your line that populates $LastSession, you might want to filter by CreationTime -- EndTIme property has a bit of a nuance in that until the job ends, its Endtime value will be 1900-01-01, and this might mess with your sorting. Use Sort-Object on the CreationTime property instead to get the most recent session.
David Domask | Product Management: Principal Analyst
Would you happen to know how to return the run days of a tape job? For example, I have a Files to Tape job that is setup in the UI to run a full backup Daily, but then have "on these days" selected and only have a single day checked (friday). I would like to be able to query jobs like this and find that they are scheduled to only run on X day and not everyday if possible. I haven't been able to find a way to do this in powershell yet.
Sure, this one is luckily quite clean. Pass the VBRFiletoTape object returned by Get-VBRTapeJob to Get-VBRJobScheduleOptions; save it to some variable and check the properties with Get-Member, you'll see all the schedule options.