Hello,
It’s possible to get job status (warning, failed or success) using powershell script?
Hello,
It’s possible to get job status (warning, failed or success) using powershell script?
I use Get-VBRJob to get the output
but when I try to filter only to show Type=”Vmware Backup” there is no result. Anyone know why?
Try this code:
Get-VBRJob | Where-Object { $_.JobType -eq "Backup" }
The column headers of the output of an array of objects in powershell do not always align to the objects’ property names. To get the correct properties for filtering, pipe a single object to “format-list” (or “fl”).
Matt's suggestion above should work to give you what you want. The other one Link State mentioned is also very good.
If you’re ever not sure on what values are accepted, check the type for a given property by calling the GetType() method. If it’s a System.Enum, you can just call the enum names with an additional method:
PS C:\Users\david.LAB> $job.JobType.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True EDbJobType System.Enum
PS C:\Users\david.LAB> $job.JobType.GetType().GetEnumNames()
Backup
Replica
Copy
...
I honestly just keep a copy of this output of enums around for quick reference when making filters with Where-Object. I usually just print a list every major release to make sure it’s current and use that as a reference.
If you aren’t sure which is which, make a job with a known type, then just get that job by name with Get-VBRJob -Name or use the -Id (you can always get the ID from the job log for a given job -- look near the beginning of a log (search ‘new log’ and then look for JobID or Job ID)
Try this code:
Get-VBRJob | Where-Object { $_.JobType -eq "Backup" }
The column headers of the output of an array of objects in powershell do not always align to the objects’ property names. To get the correct properties for filtering, pipe a single object to “format-list” (or “fl”).
Another option to list a cmdlet’s Properties is to Pipe output with the Get-Member cmdlet. I believe this lists all Properties for a given cmdlet as well.
Hello, i want to get the ‘last Result’ and wnt to know what the header name?
I try many header parameters but not get the value.
There unfortunately a little trick Veeam does with Powershell where the output of Get-VBRJob has a custom view applied to the Powershell session, and some of that data is an amalgamate from a few other options.
The last result is on CBackupSession objects returned by Get-VBRBackupSession. Get-VBRBackupSession is a bit slow unless you pass Job Ids to the -Id parameter, so I’m actually going to recommend a different way:
Get-VBRSession -Type “ type of job without square brackets ]t“ | Where-Object {$_.JobId -eq $job.id} | Sort -Property CreationTime -Descending
This will return a list of job sessions with more limited information based on the JobId you pass to it. From there you can make a PSCustomObject to reflect what you want.
There are ways to get this from the CBackupJob object returned by Get-VBRJob, but you need to use unsupported methods as far as I know, so I recommend do not go that route and use supported methods.
Similarly, the reason that GetLastResult didn’t work for you is because that is a .NET internal method. These are unsupported methods, and I do not advise using them. Methods that are read-only like this one are typically safe to use, but it’s best to avoid them. To call them in a a Select-Object statement like you’re trying, you need to follow the example here:
Get-VBRJob | Where-Object {$_.JobType -eq “Backup”} | Select Id, Name, JobType, @{n=”Last Result”;e={$_.GetLastResult()}}
PS C:\Users\david.LAB> $job | Select Id, Name, JobType, @{n="Last Result";e={$_.GetLastResult()}}
Id Name JobType Last Result
-- ---- ------- -----------
3713a1dd-8ff5-4a6d-ac24-4e89d348fffb dd-malware-box-backup Backup Success
Super…., it’s work by execute
Get-VBRJob | Where-Object {$_.JobType -eq “Backup”} | Select Id, Name, JobType, @{n=”Last Result”;e={$_.GetLastResult()}}
You’re welcome hs08, but do remember, this is an unsupported method, so if there is _any_ weirdness with it, as per Support Policy (5.8) no support for such unsupported methods.
It will work and probably will not change, but I cannot guarantee that it won’t, so I advise build your script with the PSCustomObject and Get-VBRBackupSession + Get-VBRJob as noted.
Great to see you figured out the correct syntax for the PS command and it now works.
I’m working on a Veeam PS script based on a Job’s “state”. If I run Get-VBRJob -Name <job-name> it displays a few properties..one of which is the State (i.e. Stopped or Running). But, if I place that cmd in a variable and run $Variable.State, or pipe that cmd with Select State..the State column doesn’t show the Job state..the column is blank. Any idea why
Thanks!
I’m working on a Veeam PS script based on a Job’s “state”. If I run Get-VBRJob -Name <job-name> it displays a few properties..one of which is the State (i.e. Stopped or Running). But, if I place that cmd in a variable and run $Variable.State, or pipe that cmd with Select State..the State column doesn’t show the Job state..the column is blank. Any idea why
Thanks!
You can see all properties by using Format-List
PS C:\Users\jocolon> $Job = Get-VBRJob -Name HyperV-Backup-Job
PS C:\Users\jocolon> $Job
Job Name Type State Last Result Description
-------- ---- ----- ----------- -----------
HyperV-Backup-Job Hyper-V Backup Stopped None Created by
PS C:\Users\jocolon> $Job | Format-list
LogNameMainPart : HyperV-Backup-Job
FreeBackupImpl :
IsFree : False
UserCryptoKey : Veeam.Backup.Core.CCryptoKey
Uid : 89887443-aebf-482e-921b-18e34f835c71
IsPseudoContinuousJob : False
Id : 89887443-aebf-482e-921b-18e34f835c71
Info : Veeam.Backup.Model.CDbBackupJobInfo
JobType : Backup
SourceType : HyperV
JobTargetType : Backup
TargetType : Other
TypeToString : Hyper-V Backup
Description : Created by PHARMAX\administrator at 6/30/2021 10:02 PM.
Name : HyperV-Backup-Job
BackupPlatform : EHyperV
TargetHostId : f551fdee-3479-4631-86d2-863c27440b22
TargetDir : E:\Backups
TargetFile : HyperV-Backup-Job
Options : Veeam.Backup.Model.CJobOptions
Extensions : Veeam.Backup.Core.CJobExtensions
IsContinuous : False
Additionally, the `Get-Member` command displays the properties and methods of the object.
PS C:\Users\jocolon> $Job | Get-Member
TypeName: Veeam.Backup.Core.CBackupJob
Name MemberType Definition
---- ---------- ----------
CanRunByScheduler Method bool ISchedulableJob.CanRunByScheduler()
CheckDeleteAllowed Method void CheckDeleteAllowed()
CreateJobDeletionMutex Method Veeam.Backup.Core.CMutex CreateJobDeletionMutex()
Delete Method void Delete(Veeam.Backup.Model.CModifiedUserInfo initiator)
DeleteOrMarkForDeletion Method void DeleteOrMarkForDeletion(Veeam.Backup.Model.CModifiedUserInfo modifiedBy)
DetachFromParentPolicy Method void DetachFromParentPolicy()
DisableScheduler Method void DisableScheduler(Veeam.Backup.Model.CModifiedUserInfo initiator)
EnableScheduler Method void EnableScheduler(Veeam.Backup.Model.CModifiedUserInfo initiator)
Equals
For example, to access the content of the `State` variable, you can use the `GetLastState()` method. When the `Get-VBRJob -Name HyperV-Backup-Job` cmdlet is called, the `State` property obtains its value from the `GetLastState()` method, which is accessed through a calculated property.
PS C:\Users\jocolon> $Job.GetLastState()
Stopped
PS C:\Users\jocolon>
I came across those questions and many more when I developed the AsBuiltReport.Veeam.VBR report.
PD: Exercism offers an excellent PowerShell learning track: Exercism
I’m working on a Veeam PS script based on a Job’s “state”. If I run Get-VBRJob -Name <job-name> it displays a few properties..one of which is the State (i.e. Stopped or Running). But, if I place that cmd in a variable and run $Variable.State, or pipe that cmd with Select State..the State column doesn’t show the Job state..the column is blank. Any idea why
Thanks!
Your confusion I think is coming because the Veeam Powershell Module has a custom formatting file that pretties up the console output on some cmdlets:
C:\Program Files\Veeam\Backup and Replication\Console\Veeam.Backup.PowerShell\Veeam.Backup.PowerShell.format.ps1xml
You can check this on any server where you have the remote console installed, and the relevant section for the State part is at line 228:
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Label>Job Name</Label>
<Width>25</Width>
<Alignment>left</Alignment>
</TableColumnHeader>
<TableColumnHeader>
<Label>Type</Label>
<Width>15</Width>
<Alignment>left</Alignment>
</TableColumnHeader>
<TableColumnHeader>
<Label>State</Label>
<Width>10</Width>
<Alignment>left</Alignment>
</TableColumnHeader>
<TableColumnHeader>
<Label>Last Result</Label>
<Width>12</Width>
<Alignment>left</Alignment>
</TableColumnHeader>
<TableColumnHeader>
<Label>Description</Label>
<Alignment>left</Alignment>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<ScriptBlock>$_.Name</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.TypeToString</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.GetLastState()</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.GetLastResult()</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.Description</ScriptBlock>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
You can see that it’s doing a mapping to make the display all pretty, and
So your confusion is understandable, this usually will bite you at least once as you’re working with Powershell and Veeam.
Like jcolonfzenpr tells, you can use that method if you like to check the state of the job, it’s reliable.
P.S.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.