PowerShell script exchange
Post Reply
barrett27
Enthusiast
Posts: 43
Liked: 4 times
Joined: May 18, 2022 1:58 pm
Contact:

TypeToString starting from the JobType

Post by barrett27 »

Hello,
I have a script that gives jobs sessions using:

Code: Select all

[Veeam.Backup.DBManager.CDBManager]::Instance.JobsSessions.GetSessionsByTypeAndInterval($JobType,$Start,$End)
Is there a way to have the TypeToString property of the job starting from the JobType property of the session?

Thanks,

db
david.domask
Veeam Software
Posts: 2731
Liked: 629 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: TypeToString starting from the JobType

Post by david.domask »

Hi barret27,

Not quite sure I got your question, but you want to know all possible values for the JobType argument? Or you want to find how to get the TypeToString from a CBackupSession object?

For the latter you'd need to use the JobID from the session to retrieve the job object with the relevant Get-*Job cmdlet, but I'm not confident I'm understanding your goal here.
David Domask | Product Management: Principal Analyst
barrett27
Enthusiast
Posts: 43
Liked: 4 times
Joined: May 18, 2022 1:58 pm
Contact:

Re: TypeToString starting from the JobType

Post by barrett27 »

Or you want to find how to get the TypeToString from a CBackupSession object?
Exactly.
I can take JobId from the CBackupSession objects and find a match with Id from Get-VBRJobs objects to retrieve the TypeToString, but it would take a long time with thousand sessions

db
david.domask
Veeam Software
Posts: 2731
Liked: 629 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: TypeToString starting from the JobType

Post by david.domask »

What is the need for TypeToString from the CJob objects here? Can you maybe share a few details on your script/project and what you're trying to build?

CBackupSession objects have JobTypeString and JobSourceType properties -- JobTypeString will tell if it's Backup, Replica, etc. JobSourceType will tell the workload type (e.g., VMware, Hyper-V, etc), and this might be easier that matching on the TypeToString property, but more details on what you're trying to accomplish would be great.
David Domask | Product Management: Principal Analyst
barrett27
Enthusiast
Posts: 43
Liked: 4 times
Joined: May 18, 2022 1:58 pm
Contact:

Re: TypeToString starting from the JobType

Post by barrett27 »

I'm trying to build a script that gives statistics starting from job sessions.
This is the code for the job sessions collection (in this case the $JobTypes variable is single value, Backup, but it will be a string array with more than one jobtype):

Code: Select all

$JobTypes=[Veeam.Backup.Model.EDbJobType]::Backup,
	foreach ($Type in $JobTypes) {
		$JobType=[Veeam.Backup.Model.EDbJobType]::$Type
		$JobSessions = [Veeam.Backup.DBManager.CDBManager]::Instance.JobsSessions.GetSessionsByTypeAndInterval($JobType,$Start,$End)
		foreach ($JobSession in $JobSessions) {
			[Veeam.Backup.Core.CBackupSession]::GetByOriginalSessionId($JobSession.OriginalSessionId)
		}
	}
The output will CBackupSession objects like this (filtered on the most relevant properties):

Code: Select all

PS C:\Windows\system32> $VeeamSessions[0] | Select-Object -Property *job*,Platform

JobSourceType               : VDDK
OrigJobName                 : vSphere - SQL Server - Immutable
JobType                     : Backup
IsEpAgentManagementChildJob : False
JobName                     : vSphere - SQL Server - Immutable
JobSpec                     :
JobTypeString               : Backup
JobId                       : dd5a5255-d2a4-4c3a-8b87-a140fd78c13e
JobUid                      : dd5a5255-d2a4-4c3a-8b87-a140fd78c13e
JobSess                     : Veeam.Backup.Core.CBackupSession
Platform                    : EVmware
The session above is from a job which typetostring property is:

Code: Select all

PS C:\Windows\system32> Get-VBRJob -name "vSphere - SQL Server - Immutable" | %{$_.typetostring}
VMware Backup
The goal is to have the CBackupSessions objects with their properties but also a property with "VMware Backup","Windows Agent","Linux Agent" value according to the job type.
Typetostring value is more readable for who will read the script results and doesn't know Veeam

Hope I explained myself better

db
david.domask
Veeam Software
Posts: 2731
Liked: 629 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: TypeToString starting from the JobType

Post by david.domask »

Yep, perfectly clear now on what you're trying to do.

Unfortunately there's not going to be a way to pull the TypeToString from a CBackupsession object without retrieving a CJob object first, and in my mind it's more work to pull that instead of just using a switch with conditional statements in a function somewhere to poll the CBackupSession JobTypeString and JobSourceType and match it to some value.

This is pseudo-code but I think it will save you a lot of processing time and headaches while still reporting reliably:

Code: Select all

function Get-CVBRJobTypeFromSession {
    param(
        [Veeam.Backup.Core.CBackupSession]$jobSess
        )
    switch ($jobSess){
        {$jobSess.JobSourceType -eq "VDDK" -And $jobSess.JobTypeString -eq "Replication"}{$TypeToString = "Vmware Replica"}
        {$jobSess.JobSourceType -eq "VDDK" -And $jobSess.JobTypeString -eq "Backup"}{$TypeToString = "Vmware Backup"}
        {$jobSess.JobSourceType -eq "HyperV" -And $jobSess.JobTypeString -eq "Backup"}{$TypeToString = "Hyper-V Replica"}
        {$jobSess.JobSourceType -eq "HyperV" -And $jobSess.JobTypeString -eq "Replication"}{$TypeToString = "Hyper-V Backup"}
    }
    return $TypeToString
}
It will just save you a trip to further unsupported methods with .NET reflection and also save you from having to poll it directly from the CJob objects.
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests