PowerShell script exchange
Post Reply
BADwolf
Novice
Posts: 9
Liked: never
Joined: Sep 07, 2022 6:59 pm
Full Name: Gabriel Mihm
Contact:

Export job list (Excel table)

Post by BADwolf »

Hello

I would like to output an Excel table with the following columns:

- Order (JobName)
- StartTime
- Days of the week (
- Type (incremental, copy, full)
- Backup objective
- Volume (size)
- duration (
- Retention Point (number)
- EOL

Folgendes Script hätte ich hierfür hergenommen:

Code: Select all

# Get all Backup Tasks
$bodyAllTasksBk = $null
If ($showAllTasksBk) {
  If ($taskListBk.count -gt 0) {
    If ($showDetailedBk) {
      $bodyAllTasksBk = $taskListBk | Select @{Name="VM Name"; Expression = {$_.Name}},
        @{Name="Job Name"; Expression = {$_.JobSess.Name}},
        @{Name="Start Time"; Expression = {$_.Progress.StartTime}},
        @{Name="Duration (HH:MM:SS)"; Expression = {Get-Duration -ts $_.Progress.Duration}},                    
        @{Name="Total (GB)"; Expression = {[Math]::Round($_.Progress.ProcessedSize/1GB,2)}},
     Status | Sort "Start Time"
        } 
}
not everything is included here, but even with the execution of this I do not get any output.
Unfortunately, I also have too little Powershell experience, especially in connection with Veeam, to achieve a result here.

Would be great if someone could help here.
Mildur
Product Manager
Posts: 8735
Liked: 2296 times
Joined: May 13, 2017 4:51 pm
Full Name: Fabian K.
Location: Switzerland
Contact:

Re: Ausgabe einer Auflistung (Excel Tabelle)

Post by Mildur »

Hi Gabriel

Please use English. This forum is English only :)
Your script doesn't use any GET cmdlets. No data is requested from Veeam.

Have you saw the following topic? There should be an example script:
post316372.html#p316372

Also have a look at Veeam One, which allows you to generate such reports without PowerShell.

Best,
Fabian
Product Management Analyst @ Veeam Software
BADwolf
Novice
Posts: 9
Liked: never
Joined: Sep 07, 2022 6:59 pm
Full Name: Gabriel Mihm
Contact:

Re: Ausgabe einer Auflistung (Excel Tabelle)

Post by BADwolf »

Hello;
Thank you for your reply. Well, yes.
But still, I can't get any further. Here's what I've done now:

Code: Select all

$now = Get-Date -Format yyyyMMdd_HHmm
$results_array = @()

foreach ($Job.Name) {
    $jobs = Get-VBRJob | Where-Object {$_.IsBackup}
    ForEach ($job in $jobs) {
        $lastsession = $job.FindLastSession()
        foreach ($tasksession in $lastsession.GetTaskSessions()) {
            $objResult = [pscustomobject][ordered]@{
		Server 		= $Server
               	JobName         = $job.Name
		JobStartTime    = $lastsession.CreationTime
		BackupType     	= $job.Options.BackupTargetOptions.Algorithm -replace "Syntethic", "Reversed"
                BackupSizeGB    = [Math]::Round(($lastsession.Info.BackedUpSize / 1GB), 2)
                RestorePoints   = $job.Options.BackupStorageOptions.RetainCycles
		TimeSpan_HHMMSS = [System.TimeSpan]::Parse($lastsession.EndTime - $lastsession.CreationTime)                
   		PointsOnDisk    = (Get-VBRBackup -Name $job.Name | Get-VBRRestorePoint -Name $tasksession.Name | Measure-Object).Count                
            }
            $results_array += $objResult
        }
    }
}


#Print on Screen
$results_array | sort JobName | ft autosize
If I enter this manually into Veeam PowerShell, I don't get anything back.
BADwolf
Novice
Posts: 9
Liked: never
Joined: Sep 07, 2022 6:59 pm
Full Name: Gabriel Mihm
Contact:

Re: Ausgabe einer Auflistung (Excel Tabelle)

Post by BADwolf »

So, I've made something now. but I can't get some mistakes out.

1. only a subset of backups are displayed.
2. these backups only incrementally not full.
3. I would like to format the times --> seconds are not needed
4. the volume is the same for all backups - even in different jobs.
5. in the "Dauer" column, only the "hours:minutes" display is needed
6. I can't get to the output on which days the job runs - as well as the repository path.

I want a cleaned output: The incremental jobs of a backup (with average volume and duration should be displayed) as well as the full backups.

The jobs of copy to tape and network storage should also be displayed. Probably just want too much of everything and already have a mistake right at the beginning. But maybe someone can help me?

Code: Select all

$computername = Hostname
$VeeamServers = @(
    $computername
)

$now = Get-Date -Format yyyyMMdd_HHmm
$results_array = @()

foreach ($server in $VeeamServers) {
    $jobs = Get-VBRJob | ? {$_.IsBackup}
    ForEach ($job in $jobs) {
        $lastsession = $job.FindLastSession()
        foreach ($tasksession in $lastsession.GetTaskSessions()) {
            $objResult = [pscustomobject][ordered]@{
                Auftrag      		= $job.Name
		Startzeit   		= $lastsession.CreationTime
		#Wochentage
                Sicherungstyp   	= $job.Options.BackupTargetOptions.Algorithm
		#$RepositoryPath 	= $Backup.Info.DirPath.ToString()
                Volumen      		= [math]::round($Session.Info.Progress.TotalUsedSize/1Gb,2)
		Dauer			= [System.TimeSpan]::Parse($lastsession.EndTime - $lastsession.CreationTime)
		RestorePoints   		= (Get-VBRBackup -Name $job.Name | Get-VBRRestorePoint -Name $tasksession.Name | Measure-Object).Count
		RetentionPoints		= $job.Options.BackupStorageOptions.RetainCycles	
      }
        $results_array += $objResult
        }
    }
}
       
#Export to CSV file
$CSVreportfilename = "C:\install\BackupReport-Method-Retention-" + $now + ".csv"
$results_array | sort Auftrag| Export-CSV $CSVreportfilename

#Export to HTML file
$HTMLreportfilename = "C:\install\BackupReport-Method-Retention-" + $now + ".html"
$results_array | sort Auftrag| ConvertTo-Html | Out-File $HTMLreportfilename

#Display a table on screen
$results_array | sort Auftrag| ft -AutoSize
Mildur
Product Manager
Posts: 8735
Liked: 2296 times
Joined: May 13, 2017 4:51 pm
Full Name: Fabian K.
Location: Switzerland
Contact:

Re: Ausgabe einer Auflistung (Excel Tabelle)

Post by Mildur »

Hi Gabriel

I don't have a finished script for your question. Maybe you can find more examples in our forum and https://github.com/VeeamHub which you can take to build a script for your purpose.
Let's see if someone has already a finished script for all your requirements.

A few comments from my side:
2. these backups only incrementally not full.
Your script checks for the last backup session ($job.FindLastSession()). Was the last session an incremental backup?
3. I would like to format the times --> seconds are not needed
Use something like this to convert the times: ($results_array.Startzeit).ToString("yyyy-MM-dd HH:mm")
the volume is the same for all backups - even in different jobs.
Session details are per job session and not per task session.
5. in the "Dauer" column, only the "hours:minutes" display is needed
Convert it as already mentioned.
The jobs of copy to tape and network storage should also be displayed. Probably just want too much of everything and already have a mistake right at the beginning. But maybe someone can help me?
Veeam One may still be easier than a do it yourself solution.

Best,
Fabian
Product Management Analyst @ Veeam Software
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Export job list (Excel table)

Post by oleg.feoktistov »

Hi Gabriel,

Would like to add to Fabian's comments on your points:

1. What do you mean by a subset of backups if you are iterating over backup jobs and not backups?

2. That's because you are parsing job's algorithm, not last session's algorithm. Also CBackupJob.Options.BackupTargetOptions.Algorithm property is a false friend here. It won't change if you enable active or synth fulls on the job, so you would need to search for other properties in this case.
For session algorithm see CBackupSession.Info.SessionAlgorithm.

3. Agree with Fabian, lookup formats for ToString() method on datetime object.

4. I don't know if the script you shared is the whole one you have, but as far as I see the variable used to get volume is not declared anywhere, so it might as well be cached and not redeclared. It may be the reason for the same size data reflected for different jobs:

Code: Select all

Volumen  = [math]::round($Session.Info.Progress.TotalUsedSize/1Gb,2)
5. As Fabian also mentioned, conversion is needed. Lookup formats for ToString() method on timespan object.

6. on which days the job runs - you mean a job's schedule or actual day the session is completed on?
as well as the repository path - check if you targeted any of the jobs to a scale-out repository. Getting path info is trickier for SOBR because of multiple extents, so folder name is displayed here instead.

Also, just want to clarify for myself - do you want to reflect jobs only with last sessions available or display every job regardless?

Tape and NAS backup jobs have distinct cmdlets and different properties, so some of the needed info above might be not applicable or not supported here. I advise you to start with Get-VBRTapeJob and Get-VBRNASBackupJob cmdlets and let us know if you have any questions.


Thanks,
Oleg
BADwolf
Novice
Posts: 9
Liked: never
Joined: Sep 07, 2022 6:59 pm
Full Name: Gabriel Mihm
Contact:

Re: Export job list (Excel table)

Post by BADwolf »

Hello,
sorry for the very late reply.
We try to give our customers an Excel list, in which we try to output the following data:
job name
start time
Backup type (full, incremental, differential,...)
Backup size (GB)
runtime (min)
restore points

I'm trying to create a Powerschellscript for this so that I have to create a manual list for the customers (30+).
Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests