PowerShell script exchange
dave_hill_
Novice
Posts: 6 Liked: never
Joined: Jan 22, 2021 6:38 pm
Full Name: Dave Hill
Contact:
Post
by dave_hill_ » Jan 22, 2021 6:45 pm
this post
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: 2010 Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:
Post
by oleg.feoktistov » Jan 22, 2021 8:53 pm
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:
Post
by dave_hill_ » Jan 25, 2021 4:30 pm
this post
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: 2010 Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:
Post
by oleg.feoktistov » Jan 28, 2021 7:42 pm
this post
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:
Post
by dave_hill_ » Feb 01, 2021 7:43 pm
this post
Thank you very much, i appreciate your help
oleg.feoktistov
Veeam Software
Posts: 2010 Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:
Post
by oleg.feoktistov » Feb 02, 2021 9:15 pm
this post
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:
Post
by dave_hill_ » Feb 03, 2021 5:18 pm
this post
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:
Post
by dave_hill_ » Feb 04, 2021 2:06 pm
this post
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: 2010 Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:
Post
by oleg.feoktistov » Feb 04, 2021 2:47 pm
this post
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:
Post
by dave_hill_ » Feb 04, 2021 6:24 pm
this post
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: 2010 Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:
Post
by oleg.feoktistov » Feb 09, 2021 5:51 pm
this post
Looks like Get-VBRComputerBackupJobSession ignores Where-Object condition in v10. But, as checked, should be working in v11. Thanks!
oleg.feoktistov
Veeam Software
Posts: 2010 Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:
Post
by oleg.feoktistov » Feb 11, 2021 12:33 pm
this post
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!
veremin
Product Manager
Posts: 20411 Liked: 2300 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:
Post
by veremin » Feb 16, 2021 2:21 pm
this post
No, mentioned issues are not related to the question you raised in the separate thread. Thanks!
Users browsing this forum: No registered users and 6 guests