PowerShell script exchange
Post Reply
gsassoli
Novice
Posts: 4
Liked: 1 time
Joined: Jan 27, 2025 2:21 pm
Full Name: Giacomo Sassoli
Contact:

I need some help retrievieng Schedule, RetentionPolicy and Target name for a job

Post by gsassoli »

Hello, i am quite new to Powershell Scripting, but nontheless i jumped right into veeam.powershell module because i needed to.
So far, it has been almost easy to gather some type of data out of Jobs and Job objects, however, for the love of god, i cannot find a way to correctly retrieve the Schedule, RetentionPolicy and Target name for a job.
I warn you, there is a mixture of Vmware and Veeam cmdlets, i wanted to get out a simple list of information combining both worlds.
this is what i have done so far.

Code: Select all

function Get-VBRJobDetails {
    param ()
$jobs = Get-VBRJob
$ObjectDetails = foreach ($job in $jobs) {
    Get-VBRJobObject -Job $job.name
}   
    $filteredDetails = @()
    foreach ($Objectdetail in $ObjectDetails) {
        $filteredDetails += [PSCustomObject]@{
            Name = $Objectdetail.Name
            Type = $Objectdetail.TypeDisplayName
            ResourcePool = if ($ObjectDetail.TypeDisplayName -match "Virtual Machine|Resource Pool")
                                    { Get-VM -Name $Objectdetail.Name | Select-Object -ExpandProperty ResourcePool}
                                else {""} 
            Datacenter  = if ($ObjectDetail.TypeDisplayName -match "Virtual Machine|Resource Pool")
                                    {Get-VM -Name $Objectdetail.Name | Get-Datacenter | Select-Object -ExpandProperty Name}
                                else {""}
            Cluster     =  if ($ObjectDetail.TypeDisplayName -match "Virtual Machine|Resource Pool") 
                                    {Get-VM -Name $Objectdetail.Name | Get-Cluster | Select-Object -ExpandProperty Name}
                                else {""}
            BackupName = Get-VBRJob -WarningAction SilentlyContinue | Where-Object id -EQ $ObjectDetail.Jobid[0] | Select-Object  -ExpandProperty Name
            BackupType = Get-VBRJob -WarningAction SilentlyContinue | Where-Object id -EQ $ObjectDetail.Jobid[0] | Select-Object  -ExpandProperty JobType
            BackupTarget = Get-VBRJob -WarningAction SilentlyContinue | Where-Object id -EQ $ObjectDetail.Jobid[0] | Select-Object -ExpandProperty TargetFile
}
    }
    return $filteredDetails
}

Get-VBRJobDetails | Export-Csv -Path ./Logs/VBRJobDetails.csv -NoTypeInformation

When i try to retrieve some data using Get-VBRjoboptions, i get a list of properties as:

Code: Select all

Options                     : Veeam.Backup.Common.CDomContainer
GfsPolicy                   : Veeam.Backup.GFS.Model.DOM.CDomGfsPolicy
HvReplicaTargetOptions      : Veeam.Backup.Model.CDomHvReplicaTargetOptions
ReIPRulesOptions            :
BackupStorageOptions        : Veeam.Backup.Model.CDomBackupStorageOptions
BackupTargetOptions         : Veeam.Backup.Model.CDomBackupTargetOptions
VmbSourceOptions            : Veeam.Backup.Model.CDomVmbSourceOptions
HvSourceOptions             : Veeam.Backup.Model.CDomHvSourceOptions
JobOptions                  : Veeam.Backup.Model.CDomJobOptions
ViNetworkMappingOptions     : Veeam.Backup.Model.CDomViNetworkMappingOptions
HvNetworkMappingOptions     : Veeam.Backup.Model.CDomHvNetworkMappingOptions
NotificationOptions         : Veeam.Backup.Model.CDomNotificationOptions
JobScriptCommand            : Veeam.Backup.Model.CDomJobScriptCommand
VcdReplicaTargetOptions     : Veeam.Backup.Model.CDomVcdReplicaOptions
ViReplicaTargetOptions      : Veeam.Backup.Model.CDomViReplicaTargetOptions
CloudReplicaTargetOptions   : Veeam.Backup.Model.CDomCloudReplicaTargetOptions
ViSourceOptions             : Veeam.Backup.Model.CDomViSourceOptions
GenerationPolicy            : Veeam.Backup.Model.CDomGenerationPolicy
SanIntegrationOptions       : Veeam.Backup.Model.CDomSanIntegrationOptions
ReplicaSourceOptions        : Veeam.Backup.Model.CDomReplicaSourceOptions
SqlLogBackupOptions         : Veeam.Backup.Model.CDomSqlLogBackupOptions
FailoverPlanOptions         : Veeam.Backup.Model.CDomFailoverPlanOptions
ViCloudReplicaTargetOptions : Veeam.Backup.Model.CDomViCloudReplicaTargetOptions
EpPolicyOptions             : Veeam.Backup.Model.CDomEpPolicyOptions
NasBackupRetentionPolicy    : Veeam.Backup.Model.CDomNasBackupRetentionPolicy
NasBackupOptions            : Veeam.Backup.Model.CDomNasBackupOptions
RpoOptions                  : Veeam.Backup.Model.CDomRpoOptions

Is there a way to use thees "CDom" Values?
david.domask
Veeam Software
Posts: 2644
Liked: 613 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: I need some help retrievieng Schedule, RetentionPolicy and Target name for a job

Post by david.domask »

Hi Giacomo,

Each of those CDom properties is actually an object with additional content, so you can dive into each one of those and pull further information. For example, GenerationPolicy controls the retention settings.

Schedule setting is on CJob objects returned by Get-VBRJob under the ScheduleOptions property.

For Target name, does that refer to the Repository name? If so, that is also under CJob objects with TargetRepositoryID -- pass that to Get-VBRBackupRepository to get the full repository information. Please note that if you use Scale-out Backup Repositories (SOBRs), you need to add the -Scaleout flag to Get-VBRBackupRepository. If you have a mixture of standalone and SOBRs for repositories, I would just check the result of searching by ID without the -Scalout flag first, and if the result is NULL, then test again with the -Scaleout flag.

Example:

$repoID = $job.TargetRepositoryID
$repo = Get-VBRBackupRepository | Where-Object {$_.id -eq $repoID}
If($null -eq $repo){$repo = Get-VBRBackupRepository -Scaleout | Where-Object {$_.id -eq $repoID}
David Domask | Product Management: Principal Analyst
gsassoli
Novice
Posts: 4
Liked: 1 time
Joined: Jan 27, 2025 2:21 pm
Full Name: Giacomo Sassoli
Contact:

Re: I need some help retrievieng Schedule, RetentionPolicy and Target name for a job

Post by gsassoli »

Thanks for your reply David, i am now experimenting.
In my setup i have mostly scale out repositories, anyway, running that code gives me back nothing, on a scale out or other types of repos.

I am indeed referring to the actual repository path name.
Each of those CDom properties is actually an object with additional content, so you can dive into each one of those and pull further information. For example, GenerationPolicy controls the retention settings.
Ok, but if i do a

Code: Select all

$joboptions.GenerationPolicy | get-member
on that property, it's just a plain string, can't do much with it, i am missing the purpose of Get-VBRjoboptions.
david.domask
Veeam Software
Posts: 2644
Liked: 613 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: I need some help retrievieng Schedule, RetentionPolicy and Target name for a job

Post by david.domask »

Please run $joboptins.GenerationPolicy and you will see the objects and properties held underneath it.

For example:

Code: Select all

PS C:\Users\david.LAB> $jOpts.GenerationPolicy

EnableDeletedVmDataRetention            : False
DeletedVmsDataRetentionPeriodDays       : 30
IsBackupCopySimpleMode                  : False
RecoveryPointObjectiveValue             : 1
RecoveryPointObjectiveUnit              : Day
SyncIntervalStartTime                   : 00:00:00
{truncated}


> I am indeed referring to the actual repository path name.

Ah, so to be clear, you mean if the backups are stored on a repository at C:\Backups\VeeamBackups, you want to return that path?

That gets a bit trickier especially with Scale out backup repositories (SOBR). The SOBR object is a container and underneath it will be an Extent property.

Code: Select all

PS C:\Users\david.LAB> $SOBR = Get-VBRBackupRepository -ScaleOut -Name "SOBR-FK"
PS C:\Users\david.LAB> $SOBR.Extent


ParentId   : c6cfba56-b7cd-4600-b579-5ccee43ac4fd
Repository : Veeam.Backup.Core.CBackupRepository
Status     : Normal
Role       : DataAndMeta
Name       : VBR-01-FK-Extend-01
Id         : fc4e72d9-c043-48ae-8fff-525f44fd25ac

PS C:\Users\david.LAB> $SOBR.Extent.Repository.Path.ToString()
E:\FK-Repo
See how the Extent property returns a special object with the repository information? The Repository property is an actual CBackupRepository object as returned by Get-VBRBackupRepository, and has all the same structure and properties for you to poll.


>running that code gives me back nothing

I would confirm you have the correct UUID TargetRepositoryID -- Veeam utilizes UUIDs for establishing the relationship between objects, so using the UUID is preferred in all cases to avoid ambiguous cases with strings. Can you maybe do the following:

1. Find a job targeting a SOBR
2. $Job = Get-VBRJob -name "name of the job"
3. $job.TargetRepositoryID
4. Note the UUID returned from step 3
5. $repo = Get-VBRBackupRepository -Scaleout -Name "Name of the repository"
6. $repo.id
7. Compare the UUID from step 3 and step 6, are they not the same?
David Domask | Product Management: Principal Analyst
gsassoli
Novice
Posts: 4
Liked: 1 time
Joined: Jan 27, 2025 2:21 pm
Full Name: Giacomo Sassoli
Contact:

Re: I need some help retrievieng Schedule, RetentionPolicy and Target name for a job

Post by gsassoli »

Code: Select all

~
❯ $job = get-vbrjob -name TestJob
~
❯ $joboptions = Get-VBRJobOptions -Job $job.name
~
❯ $joboptions.generationpolicy
Veeam.Backup.Model.CDomGenerationPolicy
~
❯ $joboptions
RunspaceId                  : 0397d8fa-81c8-40ed-a300-2e62af7b0b6a
Options                     : Veeam.Backup.Common.CDomContainer
GfsPolicy                   : Veeam.Backup.GFS.Model.DOM.CDomGfsPolicy
HvReplicaTargetOptions      : Veeam.Backup.Model.CDomHvReplicaTargetOptions
ReIPRulesOptions            :
BackupStorageOptions        : Veeam.Backup.Model.CDomBackupStorageOptions
BackupTargetOptions         : Veeam.Backup.Model.CDomBackupTargetOptions
VmbSourceOptions            : Veeam.Backup.Model.CDomVmbSourceOptions
HvSourceOptions             : Veeam.Backup.Model.CDomHvSourceOptions
JobOptions                  : Veeam.Backup.Model.CDomJobOptions
ViNetworkMappingOptions     : Veeam.Backup.Model.CDomViNetworkMappingOptions
HvNetworkMappingOptions     : Veeam.Backup.Model.CDomHvNetworkMappingOptions
NotificationOptions         : Veeam.Backup.Model.CDomNotificationOptions
JobScriptCommand            : Veeam.Backup.Model.CDomJobScriptCommand
VcdReplicaTargetOptions     : Veeam.Backup.Model.CDomVcdReplicaOptions
ViReplicaTargetOptions      : Veeam.Backup.Model.CDomViReplicaTargetOptions
CloudReplicaTargetOptions   : Veeam.Backup.Model.CDomCloudReplicaTargetOptions
ViSourceOptions             : Veeam.Backup.Model.CDomViSourceOptions
GenerationPolicy            : Veeam.Backup.Model.CDomGenerationPolicy
SanIntegrationOptions       : Veeam.Backup.Model.CDomSanIntegrationOptions
ReplicaSourceOptions        : Veeam.Backup.Model.CDomReplicaSourceOptions
SqlLogBackupOptions         : Veeam.Backup.Model.CDomSqlLogBackupOptions
FailoverPlanOptions         : Veeam.Backup.Model.CDomFailoverPlanOptions
ViCloudReplicaTargetOptions : Veeam.Backup.Model.CDomViCloudReplicaTargetOptions
EpPolicyOptions             : Veeam.Backup.Model.CDomEpPolicyOptions
NasBackupRetentionPolicy    : Veeam.Backup.Model.CDomNasBackupRetentionPolicy
NasBackupOptions            : Veeam.Backup.Model.CDomNasBackupOptions
RpoOptions                  : Veeam.Backup.Model.CDomRpoOptions
VmbJobOptions               :
IsBackupCopyGfsEnabled      : False

This is what i am getting.
I feel dumb, i can't understand how you are getting something out of that property.
Sorry about that..
david.domask
Veeam Software
Posts: 2644
Liked: 613 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: I need some help retrievieng Schedule, RetentionPolicy and Target name for a job

Post by david.domask »

No worries, that is unusual, it should just pop out the information like my animation below.

Can you run:

$PSVersionTable.PSVersion

From your shell and show the output? Also are you testing in Powershell ISE by chance?

Example of how it should go:

Image
David Domask | Product Management: Principal Analyst
gsassoli
Novice
Posts: 4
Liked: 1 time
Joined: Jan 27, 2025 2:21 pm
Full Name: Giacomo Sassoli
Contact:

Re: I need some help retrievieng Schedule, RetentionPolicy and Target name for a job

Post by gsassoli » 1 person likes this post

I found the problem!

i was importing the module from a powershell session to he veeam server.
Running theese cmdlets locally i get the desired results !
Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests