Hi
@Valdemar,
I think this is actually behavior of Select-Object, not of Veeam. Check this line from the documentation:
https://docs.microsoft.com/en-us/powers ... escription
When you include a Select-Object command with the First or Index parameters in a command pipeline, PowerShell stops the command that generates the objects as soon as the selected number of objects is generated, even when the command that generates the objects appears before the Select-Object command in the pipeline. To turn off this optimizing behavior, use the Wait parameter.
In fact I did see the same behavior you did, but using the -Wait parameter and it works as you're expecting it to. My guess is that the stop just dumps STDOUT to the console as per the Select-Object design described above, and my below test by allowing Get-VBRTapeJob to run in full first makes it behave right also.
Code: Select all
PS C:\Users\Administrator> $tjob = (Get-VBRTapeJob) | Select-Object -First 1
PS C:\Users\Administrator> $tjob
FullBackupPolicy : WeeklyOnDays
Object : {vmware-fi-nixsobr, vmware-ffi-day-retention, vmware-pervm-ffi, template-backup}
ProcessIncrementalBackup : True
So I suppose it's just that with your current code, it terminates the pipeline (including the variable saving) per Select-Object behavior.
You can workaround this by using the -outvariable parameter at the end of your pipeline (and further piping to Out-Null). Note you do not prefix the variable with $ when using -OutVariable
Code: Select all
PS C:\Users\Administrator> Get-VBRBackupSession | Select-Object -First 1 -OutVariable Firstsession |Out-Null
PS C:\Users\Administrator> $Firstsession
Job Name State Start Time End Time Result
-------- ----- ---------- -------- ------
support2\ddomask_... Stopped 7/3/2022 23:00:34 7/3/2022 23:44:03 Failed
Now, as to why Get-Service behaves differently, regrettably I can't tell you
Personally I suspect custom private optimizations on the built-in Windows cmdlets, but I have no proof for this, it's just a guess.
But if the goal is to do a speed optimization and just return the first result, I'm not sure there's a good way to do this with Select-Object; the result will always be unpredictable anyways without some sorting from Sort-Object or other sorting, so maybe you can describe what you're trying to do a bit more and we can optimize the result based on that.