This is a weird behavior of
Get-VBRBackupSession. The '-Name' parameter matches the session name, but the session name in many cases has added text to indicate the run type, for example, if you have a job that is named "MyBackup" but you actually look at the session names you'll see:
MyBackup (Full)
MyBackup (Incremental)
The easy workaround for this is to just use a wildcard character after the job name like this:
Code: Select all
Get-VBRBackupSession -Name "MyBackup*" | Get-VBRTaskSession
Another options is to use a filter:
Code: Select all
Get-VBRBackupSession | ?{$_.JobName -eq "MyBackup"} | Get-VBRTaskSession
Get-VBRBackupSession is quite a heavy command, so if I know I'm going to reference backup sessions a lot in the script I usually just load them up into pre-sorted hash table using either JobName or JobId as the key, for example like so:
Code: Select all
$BackupSessions = Get-VBRBackupSession | Sort JobName, CreationTime | Group-Object -Property JobName -AsHashTable
Then you can reference any backup sessions for any jobs with $BackupSessions.'<Job_Name>' extremely quickly. You could also add a filter to the above code to grab on the most recent X number of days, especially if you have lots of sessions.
If you're just looking for the most recent/currently active session then something like this should work and be very fast:
Code: Select all
Get-VBRJob -Name "<Job_Name>").FindLastSession() | Get-VBRTaskSession