PowerShell script exchange
Post Reply
marius roma
Veteran
Posts: 459
Liked: 5 times
Joined: Feb 01, 2012 12:04 pm
Full Name: Mario
Contact:

Listing all the times all VMs were replicated

Post by marius roma »

In order to perform statistic analysis I need to create a job to list all the times all VMs were replicated or at least the last 50 time each VM was replicated, regardless of the job.
For each time a given VM was replicated I need to record the start and end time and the rersult (Success, warning, failed...).
The task could be described as something like "For each VM in each job list all the times the VM was replicated".
I made some tests but the results I get are not complete, so I presume I am getting the wrong data.
Is there any sample script I can start from?
Regards
marius
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Listing all the times all VMs were replicated

Post by veremin »

Should it be a list of replicated VMs that still have restore points or more like historical report that will provide information regarding even those VMs that already have no replication restore points?
marius roma
Veteran
Posts: 459
Liked: 5 times
Joined: Feb 01, 2012 12:04 pm
Full Name: Mario
Contact:

Re: Listing all the times all VMs were replicated

Post by marius roma »

The second Solution would be far better...
Regards
marius
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Listing all the times all VMs were replicated

Post by veremin » 1 person likes this post

Unfortunately, I'm out of the office at the moment (on a sick leave, actually), so, I can only propose the algorithm that I'd implement.

Firstly, I'd get the list of all sessions, using Get-VBRBackupSession commandlet.

Secondly, I'd filter out those that are not replication ones (type is not equal to replica) via where-object commandlet.

Thirdly, I'd leverage Get-VBRTaskSession commandlet to get all VMs specific sessions within replication job sessions.

Fourthly, I'd select specific properties out of the list of existing task session, like VM name, result, start and end time.

Fifthly, I'd format the output a bit, so that, information is shown in required order (all sessions specific to first VM, then, to second, etc.)

Thanks.
marius roma
Veteran
Posts: 459
Liked: 5 times
Joined: Feb 01, 2012 12:04 pm
Full Name: Mario
Contact:

[MERGED] Listing session start and end time

Post by marius roma »

I need to get a list of the last 10 backup sessions for each job with start time, end time and result.
I need to detect as well if health check was performed for the given session.
My code looks like:

Code: Select all

foreach ($Job in (Get-VBRJob | where {$_.JobType -eq "Backup"}))
    {
    foreach ($Session in (Get-VBRBackupSession | Where {$_.Jobname -eq $Job.name}) | Sort creationtime -Descending | select -First 10)
        {
        ...
        $session_start =
        $session_end =
        $session_result = 
        $session_Health_Check = 
        ...
        }
     }
Which properties should I use to get the values I need?
Regards
Marius
marius roma
Veteran
Posts: 459
Liked: 5 times
Joined: Feb 01, 2012 12:04 pm
Full Name: Mario
Contact:

Re: Listing all the times all VMs were replicated

Post by marius roma »

Any update?
Regards
marius
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Listing all the times all VMs were replicated

Post by veremin »

The general approach is described above, and multiple examples of how the requested information can be received are available on our forums. Thanks.
marius roma
Veteran
Posts: 459
Liked: 5 times
Joined: Feb 01, 2012 12:04 pm
Full Name: Mario
Contact:

Re: Listing all the times all VMs were replicated

Post by marius roma »

I am working with a script based on the following loops:

Code: Select all

foreach ($Job in (Get-VBRJob | where {$_.JobType -eq "Backup"}))
 {
 foreach ($Session in (Get-VBRBackupSession | Where {$_.Jobname -eq $Job.name}) | Sort creationtime -Descending | select -First 3)
     {
     ...
     ...
     }
 }
It works, but it looks extremely slooooow.
Can anybody please suggest a smarter aproach?
Regards
Marius
veremin
Product Manager
Posts: 20270
Liked: 2252 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Listing all the times all VMs were replicated

Post by veremin »

You might try to run backup session only once, save the results into hash table and operate with the hash table afterwards; should save you the time, since the Get-VBRBackupSession cmdlet will be executed only once. Thanks.
Post Reply

Who is online

Users browsing this forum: Max93 and 20 guests