Host-based backup of Microsoft Hyper-V VMs.
Post Reply
robnicholsonmalt
Expert
Posts: 116
Liked: 12 times
Joined: Dec 21, 2018 11:42 am
Full Name: Rob Nicholson
Contact:

Get session information for Hyper-V jobs via PowerShell

Post by robnicholsonmalt »

We use a PowerShell maintenance script to check all is well. One of the things it does is make sure Veeam jobs ran over the last 24 hours. This is the code:

Code: Select all

# CheckVeeamJob: check when Veeam job last ran.
Function CheckVeeamJob($Id, $Name) {
	Write-Host "Checking Veeam $Name job"
	$Job = Get-VBRComputerBackupJob -Id $Id -EA Silent
	If (!$Job) {WriteFault "Can't find Veeam backup job for $Name"; Return}
	$Sessions = Get-VBRComputerBackupJobSession -Name $Job.Name | ? Result -eq "Success" | Sort CreationTime -Descending
	If (!$Sessions) {WriteFault "Can't find any success jobs for $Name"; Exit}
	$LastSession = $Sessions[0]
	$Elapsed = New-TimeSpan $LastSession.CreationTime (Get-Date)
	If ($Elapsed.TotalHours -gt 25) {WriteFault ("$Name backup job not run successfully for over 24 hours. Last run {0:N} hours ago" -f $Elapsed.TotalHours)}
}
Works fine for computer backups but Get-VBRComputerBackupJob fails for Hyper-V backup jobs (not too surprising). There isn't a Get-VBRHvBackupJob cmdlet so bit stumped how I can do the same for those types of jobs? Considering there are 1,255 Veeam cmdlets, I thought I'd ask before spending hours pouring over the docs :-)
ronnmartin61
Veeam Software
Posts: 441
Liked: 131 times
Joined: Mar 07, 2016 3:55 pm
Full Name: Ronn Martin
Contact:

Re: Get session information for Hyper-V jobs via PowerShell

Post by ronnmartin61 »

Get-VBRJob and filter on the job types you want to retrieve. Get-VBRComputerBackupJob is for agent backups
robnicholsonmalt
Expert
Posts: 116
Liked: 12 times
Joined: Dec 21, 2018 11:42 am
Full Name: Rob Nicholson
Contact:

Re: Get session information for Hyper-V jobs via PowerShell

Post by robnicholsonmalt »

Get-VBRJob reports that it's going to be retired?
ronnmartin61
Veeam Software
Posts: 441
Liked: 131 times
Joined: Mar 07, 2016 3:55 pm
Full Name: Ronn Martin
Contact:

Re: Get session information for Hyper-V jobs via PowerShell

Post by ronnmartin61 »

Yes but only for agent backups
robnicholsonmalt
Expert
Posts: 116
Liked: 12 times
Joined: Dec 21, 2018 11:42 am
Full Name: Rob Nicholson
Contact:

Re: Get session information for Hyper-V jobs via PowerShell

Post by robnicholsonmalt » 1 person likes this post

Ahh.... that wasn't clear. Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests