PowerShell script exchange
Post Reply
dave_hill_
Novice
Posts: 6
Liked: never
Joined: Jan 22, 2021 6:38 pm
Full Name: Dave Hill
Contact:

Agent - Getting hostname / success info from jobs?

Post by dave_hill_ »

I'm able to successfully pull all the hostnames, statuses, and last runtimes from get-vbrjob for my VIRTUAL hosts, however i want this same information for my Agent hosts as well. (Basically this script confirms a host was recently / successfully backed up prior to applying updates to the machines)

Code: Select all

$timespan = new-timespan -days 2
try{
    foreach($Job in (Get-VBRJob))
    {
	    $Session = $Job.FindLastSession()
        $lastrun = $Job.LatestRunLocal
	    if(!$Session){continue;}
	    $Tasks = $Session.GetTaskSessions()
        foreach($task in $tasks){
            $hostinfo = $task | select Name, Status
            if (((get-date) - $lastrun) -gt $timespan) {
                "$($hostinfo.Name) $($hostinfo.Status) NOTREADY" | add-content "UpdateStatus"
            } else {
                "$($hostinfo.Name) $($hostinfo.Status) READY" | add-content "UpdateStatus"
            }
        }
    }
    ........

However, i cannot seem to find this same information within Get-VBRComputerBackupJob, or any other module for that matter. Can someone help me find this info for my physical hosts?

oleg.feoktistov
Veeam Software
Posts: 971
Liked: 356 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Agent - Getting hostname / success info from jobs?

Post by oleg.feoktistov » 1 person likes this post

Hi Dave,

Yes, VBRComputerBackupJob class is missing dynamic methods CBackupJob class has. However, that's not a problem.
Just use cmdlets designed specifically for agents and apply some filtering:

Code: Select all

$timespan = new-timespan -days 2
$jobs = Get-VBRComputerBackupJob
$sessions = Get-VBRComputerBackupJobSession
try{
    foreach($Job in $jobs)
    {
	    $Session = $sessions| where {$_.JobId -eq $Job.Id} | select -Last 1
        $lastrun = $Session.CreationTime
	    if(!$Session){continue;}
	    $Tasks = Get-VBRTaskSession -Session $Session
        foreach($task in $tasks){
            $hostinfo = $task | select Name, Status
            if (((get-date) - $lastrun) -gt $timespan) {
                "$($hostinfo.Name) $($hostinfo.Status) NOTREADY" | add-content "UpdateStatus"
            } else {
                "$($hostinfo.Name) $($hostinfo.Status) READY" | add-content "UpdateStatus"
            }
        }
    }
Best regards,
Oleg

dave_hill_
Novice
Posts: 6
Liked: never
Joined: Jan 22, 2021 6:38 pm
Full Name: Dave Hill
Contact:

Re: Agent - Getting hostname / success info from jobs?

Post by dave_hill_ »

I appreciate your help, however I hit an issue with your code. This portion of the code does not return any tasks, thus i get no host info.

Code: Select all

$Tasks = Get-VBRTaskSession -Session $Session

Example:

Code: Select all

PS C:\xxxxxxxx\WindowsServerUpdates>  $Session = $sessions| where {$_.JobId -eq $Job.Id} | select -Last 1
PS C:\xxxxxxxxxx\WindowsServerUpdates> $Session


CreationTime : 1/26/2020 8:00:11 PM
EndTime      : 1/26/2020 8:13:07 PM
JobId        : e5933313-71ef-428e-89cf-75fb648e61af
Result       : Success
State        : Stopped
Id           : a356d2e9-55a3-49bc-9b0b-efcebc4d1d43

PS C:\xxxxxxxxx\WindowsServerUpdates> Get-VBRTaskSession -Session $Session

PS C:\xxxxxxxxxx\WindowsServerUpdates> 

oleg.feoktistov
Veeam Software
Posts: 971
Liked: 356 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Agent - Getting hostname / success info from jobs?

Post by oleg.feoktistov »

That's interesting. Now it stopped working in my lab as well. I'll look into it and share an update right after. Thanks!

dave_hill_
Novice
Posts: 6
Liked: never
Joined: Jan 22, 2021 6:38 pm
Full Name: Dave Hill
Contact:

Re: Agent - Getting hostname / success info from jobs?

Post by dave_hill_ »

Thank you very much, i appreciate your help

oleg.feoktistov
Veeam Software
Posts: 971
Liked: 356 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Agent - Getting hostname / success info from jobs?

Post by oleg.feoktistov »

To some reason, Get-VBRComputerBackupJobSession cmdlet ignores select -Last 1 part regardless the scripting environment.
Though, I figured that it works with some tweaks. Amendments are below:

Code: Select all

$Session = Get-VBRComputerBackupJobSession | where {$_.JobId -eq $Job.Id} | sort -Property CreationTime -Descending
$lastrun = $Session.CreationTime
if(!$Session){continue;}
$Tasks = Get-VBRTaskSession -Session $Session[0]
Hope it helps,
Oleg

dave_hill_
Novice
Posts: 6
Liked: never
Joined: Jan 22, 2021 6:38 pm
Full Name: Dave Hill
Contact:

Re: Agent - Getting hostname / success info from jobs?

Post by dave_hill_ »

Weird, I'm still having trouble. I had to modify your code above due to some syntax errors.

Code: Select all

$sessions = Get-VBRComputerBackupJobSession
        foreach($Job in Get-VBRComputerBackupJob)
        {
	        $Session = $sessions | where {$_.JobId -eq $Job.Id} | sort -Property CreationTime -Descending
            $lastrun = $Session[0].CreationTime
	        if(!$Session){continue}
	        $Tasks = Get-VBRTaskSession -Session $Session[0]
            foreach($task in $tasks){
                $hostinfo = $task | select Name, Status
                if (((get-date) - $lastrun) -gt $timespan) {
                    "$($hostinfo.Name) $($hostinfo.Status) NOTREADY" | add-content "UpdateStatus"
                } else {
                    "$($hostinfo.Name) $($hostinfo.Status) READY" | add-content "UpdateStatus"
                }
            }
        }

Manually running the specific portions, still no return from Get-VBRTaskSession

Code: Select all

PS C:\Windows\system32> $Session[0]


CreationTime : 2/2/2021 11:00:20 PM
EndTime      : 2/2/2021 11:04:10 PM
JobId        : 1a3f9745-43e9-4ab6-8a39-2d945fe8a4be
Result       : Success
State        : Stopped
Id           : 2a499c0f-275a-49c4-ac1b-227aeac98f76




PS C:\Windows\system32> $Session[0].CreationTime

Tuesday, February 2, 2021 11:00:20 PM



PS C:\Windows\system32> Get-VBRTaskSession -Session $Session[0]

PS C:\Windows\system32> 

dave_hill_
Novice
Posts: 6
Liked: never
Joined: Jan 22, 2021 6:38 pm
Full Name: Dave Hill
Contact:

Re: Agent - Getting hostname / success info from jobs?

Post by dave_hill_ »

Ok i see what happened. I need to explicitly call Get-VBRComputerBackupJobSession | where {$_.JobId -eq $Job.Id} - i cannot set $sessions = Get-VBRComputerBackupJobSession and then parse it. Very weird.

Thank you for your help

oleg.feoktistov
Veeam Software
Posts: 971
Liked: 356 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Agent - Getting hostname / success info from jobs?

Post by oleg.feoktistov »

Yes, sorry, I just failed to past this cmdlet into the corresponding row. And I noted to duly check it with QA after upcoming release. Thanks!

dave_hill_
Novice
Posts: 6
Liked: never
Joined: Jan 22, 2021 6:38 pm
Full Name: Dave Hill
Contact:

Re: Agent - Getting hostname / success info from jobs?

Post by dave_hill_ »

Actually, even this pipe is broken. I set the filter like you have, and i still get all jobs back (the where-object does not seem to work when piped). It doens't return me a filtered list. So when i do my loop, i'm getting the same results for session[0] because the results im trying to get are not filtering properly

Get-VBRComputerBackupJobSession | where {$_.JobId -eq $Job.Id}

oleg.feoktistov
Veeam Software
Posts: 971
Liked: 356 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Agent - Getting hostname / success info from jobs?

Post by oleg.feoktistov »

Looks like Get-VBRComputerBackupJobSession ignores Where-Object condition in v10. But, as checked, should be working in v11. Thanks!

oleg.feoktistov
Veeam Software
Posts: 971
Liked: 356 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Agent - Getting hostname / success info from jobs?

Post by oleg.feoktistov »

Double checked with QA due to inconsistent output in various builds and here is the conclusions we made:
  • Confirmed a bug with Get-VBRComputerBackupJobSession filtering. To be fixed in vNext.
  • Get-VBRTaskSession doesn't work properly with agent sessions. Planned an enhancement for further version.
Thanks!

Henrik.Grevelund
Expert
Posts: 100
Liked: 12 times
Joined: Feb 13, 2017 2:56 pm
Full Name: Henrik Grevelund
Contact:

Re: Agent - Getting hostname / success info from jobs?

Post by Henrik.Grevelund »

Hi Oleg,

Are these bug's also the reason for me not being able to filter out the Agent translog jobs ?
powershell-f26/how-to-find-agent-sql-tr ... 72058.html
Have nice day,
Henrik

veremin
Product Manager
Posts: 18541
Liked: 1851 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Agent - Getting hostname / success info from jobs?

Post by veremin »

No, mentioned issues are not related to the question you raised in the separate thread. Thanks!

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests