PowerShell script exchange
Post Reply
shahn
Influencer
Posts: 15
Liked: 2 times
Joined: Sep 04, 2023 7:48 am
Contact:

backup report powershell questions

Post by shahn »

Hi,
i have a questions.

I used the powershell script for the backup report

[powershell script]

Code: Select all

$sessions =Get-VBRComputerBackupJobSession | ?{$_.CreationTime -ge (Get-Date).AddDays(-7)}
foreach ($session in $sessions) {
  Get-VBRTaskSession -Session $session | Select-Object -Property JobName, Name,@{n='Result';e={$_.Status}},@{n='StartTime';e={$_.Progress.StartTimeLocal}},@{n='EndTime';e={$_.Progress.StopTimeLocal}},@{n='Backup Size MB';e={[math]::Round(($_.Progress.TransferedSize/1024/1024),2)}} | Sort CreationTime | Format-Table >> C:\report_$dt.txt
}
[Report result]

Code: Select all

[
JobName         Name       Result StartTime             EndTime               Backup Size MB
-------         ----       ------ ---------             -------               --------------
72workstation-2 72-window Success 2024-04-04 오후 9:00:53 2024-04-04 오후 9:00:56              0

JobName                        Name       Result StartTime             EndTime               Backup Size MB
-------                        ----       ------ ---------             -------               --------------
72workstation-2 - 192.168.1.72 72-window Success 2024-04-05 오후 2:52:11 2024-04-05 오후 3:24:07       11911.38
]
I want there's only one column

example

Code: Select all

JobName         Name       Result StartTime             EndTime               Backup Size MB
-------         ----       ------ ---------             -------               --------------
72workstation-2 72-window Success 2024-04-04 오후 9:00:53 2024-04-04 오후 9:00:56              0
72workstation-2 - 192.168.1.72 72-window Success 2024-04-05 오후 2:52:11 2024-04-05 오후 3:24:07       11911.38

but, i don't know where to fix script

Please give me some advice!

Thank you
david.domask
Veeam Software
Posts: 1858
Liked: 447 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: backup report powershell questions

Post by david.domask »

Hi shahn,

Powershell is doing what is expected here since your loop calls Get-VBRTaskSession multiple times, so it's printing the output for each item in your array individually.

Try it something like this:

Code: Select all

$TaskSessions = @()
$sessions = Get-VBRComputerBackupJobSession | Where-Object{$_.CreationTime -ge (Get-Date).AddDays(-7)}
foreach ($session in $sessions) {
  $TaskSessions += Get-VBRTaskSession -Session $session | Select-Object -Property JobName, Name,@{n='Result';e={$_.Status}},@{n='StartTime';e={$_.Progress.StartTimeLocal}},@{n='EndTime';e={$_.Progress.StopTimeLocal}},@{n='Backup Size MB';e={[math]::Round(($_.Progress.TransferedSize/1024/1024),2)}} 
}

$TaskSessions | Sort -Property CreationTime -Descending

Then you should get your single list like you're hoping. We initialize an empty array to add some items to, then use += to add new data to that array and simply print the array at the end.
David Domask | Product Management: Principal Analyst
shahn
Influencer
Posts: 15
Liked: 2 times
Joined: Sep 04, 2023 7:48 am
Contact:

Re: backup report powershell questions

Post by shahn » 1 person likes this post

Thank you for your advice!

Result

Code: Select all

Name              Result StartTime              EndTime                Backup Size MB
----              ------ ---------              -------                --------------
89-rhel6         Success 2024-03-19 오전 11:13:39 2024-03-19 오전 11:20:10        6087.18
84-cvt           Warning 2024-03-19 오후 10:00:41 2024-03-19 오후 10:05:05        2052.88
84-cvt           Warning 2024-03-20 오후 10:00:43 2024-03-20 오후 10:07:07        6468.77
84-cvt           Warning 2024-03-18 오후 10:00:52 2024-03-18 오후 10:07:16        1851.56
83-win           Warning 2024-03-16 오후 10:00:55 2024-03-16 오후 10:05:17         182.39
84-cvt           Warning 2024-03-17 오후 10:00:57 2024-03-17 오후 10:05:20        2098.64
83-win           Warning 2024-03-17 오후 10:01:02 2024-03-17 오후 10:05:25         326.45

so, i have a question more.

Is it Possible 'Name' in descending order? or ascending

Example

Code: Select all

Name              Result StartTime              EndTime                Backup Size MB
----              ------ ---------              -------                --------------
83-win           Warning 2024-03-17 오후 10:01:02 2024-03-17 오후 10:05:25         326.45
83-win           Warning 2024-03-16 오후 10:00:55 2024-03-16 오후 10:05:17         182.39
84-cvt           Warning 2024-03-19 오후 10:00:41 2024-03-19 오후 10:05:05        2052.88
84-cvt           Warning 2024-03-20 오후 10:00:43 2024-03-20 오후 10:07:07        6468.77
84-cvt           Warning 2024-03-18 오후 10:00:52 2024-03-18 오후 10:07:16        1851.56
84-cvt           Warning 2024-03-17 오후 10:00:57 2024-03-17 오후 10:05:20        2098.64
89-rhel6         Success 2024-03-19 오전 11:13:39 2024-03-19 오전 11:20:10        6087.18
shahn
Influencer
Posts: 15
Liked: 2 times
Joined: Sep 04, 2023 7:48 am
Contact:

Re: backup report powershell questions

Post by shahn » 1 person likes this post

Oh, I found it!
david.domask
Veeam Software
Posts: 1858
Liked: 447 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: backup report powershell questions

Post by david.domask »

Glad you figured it out shahn :) I'm guessing you just piped to Sort-Object -Property Name, correct?

Any time you need to do sorts, just pipe the array/list/whatever to Sort-Object it will set you right. You can also use Group-Object, but this will return a very specific object, so play with it a bit and get a feel for how it does the sorting (it's very similar in my mind to Pivot Tables from Excel if that helps your mental model)
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests