PowerShell script exchange
Post Reply
Deansbkk
Influencer
Posts: 18
Liked: never
Joined: Feb 23, 2010 6:13 am
Full Name: Dean S
Contact:

PS to report on Last Backup

Post by Deansbkk »

Hello,

We'd like to run a simple PS script that lists all VM's on a host and when the Last Backup was.

These commands will accomplish the first part (list all VM's on a host)
$server = Get-VBRServer -Name "Hyperv01"
Find-VBRHvEntity -Server $server -HostsAndVMs

But we've yet to find the PS cmdlet to retreive the Last Backup details. The Last Backup details we're referring to as the same as we can see in the GUI when looking at Inventory > Microsoft Hyper-V > Standalone Hosts > Servername

Image
https://1drv.ms/i/s!AhTehwTjzaiAkyI6eJ9 ... k?e=eKAK2V

Thank you!
ronnmartin61
Veeam Software
Posts: 535
Liked: 184 times
Joined: Mar 07, 2016 3:55 pm
Full Name: Ronn Martin
Contact:

Re: PS to report on Last Backup

Post by ronnmartin61 »

There isn't a single cmdlet that will return a list of last restore points however post493339.html?hilit=last%20backup#p493339 should point you in the right direction.
david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: PS to report on Last Backup

Post by david.domask »

To add to @ronnmartin61's answer (which I guess includes my answer :D), that is how I was going to recommend this also.

But @Deansbkk, can I ask, how do you have the VMs added to the job? Individually or some hierarchy object like a folder or tags or host?

The reason I ask is I might have some code already that you can repurpose, but it will only work for manually added VMs :(
David Domask | Product Management: Principal Analyst
Deansbkk
Influencer
Posts: 18
Liked: never
Joined: Feb 23, 2010 6:13 am
Full Name: Dean S
Contact:

Re: PS to report on Last Backup

Post by Deansbkk »

@david.domask No that's the issue (VM hasn't been added to a job). If we see a VM 'Last Backup' is never then it would alert us it's missed being added to a backup job.

Since we can easily see the 'Last Backup' info via the GUI I had hoped it would be easy to grab that info via PS, but perhaps not.

Thanks!
rovshan.pashayev
Veeam Software
Posts: 443
Liked: 94 times
Joined: Jul 03, 2023 12:44 pm
Full Name: Rovshan Pashayev
Location: Czechia
Contact:

Re: PS to report on Last Backup

Post by rovshan.pashayev » 2 people like this post

Hello Deansbkk,

You can try running the following PowerShell script, which will take your Hyper-V name as input and list VM names with their last restore points. However, the script may take some time to finish, depending on your environment.

Code: Select all

$vms = Find-VBRHvEntity | where {$_.VmHostName -eq "your-example-hyperv-name" }


foreach ($vm in $vms) 
{ 
    $restorePoint = Get-VBRRestorePoint | where {$_.VMName -eq $vm.Name} | Sort-Object -Property CreationTime -Descending | Select-Object -First 1
    Write-Host "VM Name: $($vm.Name), Last Restore Point: $($restorePoint.CreationTime)"
}
Rovshan
Rovshan Pashayev
Analyst
Veeam Agent for Linux, Mac, AIX & Solaris
david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: PS to report on Last Backup

Post by david.domask »

Oh, thank you @rovshan.pashayev!

@Deansbkk will this suffice for your needs?
David Domask | Product Management: Principal Analyst
Deansbkk
Influencer
Posts: 18
Liked: never
Joined: Feb 23, 2010 6:13 am
Full Name: Dean S
Contact:

Re: PS to report on Last Backup

Post by Deansbkk »

@rovshan.pashayev and @david.domask thank you very much.

This will easily work for what we need!
Deansbkk
Influencer
Posts: 18
Liked: never
Joined: Feb 23, 2010 6:13 am
Full Name: Dean S
Contact:

Re: PS to report on Last Backup

Post by Deansbkk »

I spoke too soon! Would you be able to help change the script from 'write-host' to export to csv?

I've tried some different PS code using arrays but so far have not been able to cobble anything together that works. Thank you
david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: PS to report on Last Backup

Post by david.domask »

Hi @Deansbkk, try just doing instead of Write-Host and instead adding that information to an array.

Code: Select all

$vms = Find-VBRHvEntity | where {$_.VmHostName -eq "your-example-hyperv-name" }
$AllMachinesReport = @() #initialize the array
$AllRPs = Get-VBRRestorePoint #We get all RPs here to avoid calling Get-VBRRestorePoint multiple times in the loop; this will take longer initially, but be way faster in the long run
foreach ($vm in $vms) 
{ 
    $restorePoint = $AllRPs | Where-Object{$_.VMName -eq $vm.Name} | Sort-Object -Property CreationTime -Descending | Select-Object -First 1
    $VMObject = [PSCustomObject]@{
         VM_Name =  "$vm.Name"
         Last_Restore_point = "$restorePoint.CreationTime"
     }
    $AllMachinesReport += $VMObject
}
$AllMachinesReport | Export-CSV -NoTypeInformation C:\temp\output.csv; start C:\temp
David Domask | Product Management: Principal Analyst
Deansbkk
Influencer
Posts: 18
Liked: never
Joined: Feb 23, 2010 6:13 am
Full Name: Dean S
Contact:

Re: PS to report on Last Backup

Post by Deansbkk »

@david.domask thank you. Something is not quite right as the output from this is:

"VM_Name","Last_Restore_point"
"Veeam.Backup.Core.HyperV.Infrastructure.CHvVmItem.Name","Veeam.Backup.Core.COib.CreationTime"
"Veeam.Backup.Core.HyperV.Infrastructure.CHvVmItem.Name","Veeam.Backup.Core.COib.CreationTime"
"Veeam.Backup.Core.HyperV.Infrastructure.CHvVmItem.Name","Veeam.Backup.Core.COib.CreationTime"
"Veeam.Backup.Core.HyperV.Infrastructure.CHvVmItem.Name",".CreationTime"
david.domask
Veeam Software
Posts: 2123
Liked: 513 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: PS to report on Last Backup

Post by david.domask »

ah, give me a bit, I forgot we'll need to convert it to strings :)
David Domask | Product Management: Principal Analyst
rovshan.pashayev
Veeam Software
Posts: 443
Liked: 94 times
Joined: Jul 03, 2023 12:44 pm
Full Name: Rovshan Pashayev
Location: Czechia
Contact:

Re: PS to report on Last Backup

Post by rovshan.pashayev » 1 person likes this post

Hello Deansbkk,

Below is a script that generates a CSV file containing a list of VMs and their corresponding restore points. However, the script has been enhanced to include only those VMs that actually have restore points, eliminating any VMs without such backups.

Code: Select all

$vms = Find-VBRHvEntity | where {$_.VmHostName -eq "your-example-hyperv-name" }
$AllMachinesReport = @() #initialize the array
$AllRPs = Get-VBRRestorePoint #We get all RPs here to avoid calling Get-VBRRestorePoint multiple times in the loop; this will take longer initially, but be way faster in the long run
foreach ($vm in $vms) 
{ 
    $restorePoint = $AllRPs | Where-Object{$_.VMName -eq $vm.Name} | Sort-Object -Property CreationTime -Descending | Select-Object -First 1
    if ($vm -ne $null -and $restorePoint -ne $null) {
        $VMObject = [PSCustomObject]@{
             VM_Name =  $vm.Name.ToString()
             Last_Restore_point = $restorePoint.CreationTime.ToString()
         }
        $AllMachinesReport += $VMObject
    }
}
$AllMachinesReport | Export-CSV -NoTypeInformation C:\temp\output.csv; start C:\temp
Rovshan
Rovshan Pashayev
Analyst
Veeam Agent for Linux, Mac, AIX & Solaris
NK100251
Influencer
Posts: 16
Liked: never
Joined: Jan 28, 2022 1:08 am
Full Name: Neha Karan
Contact:

Re: PS to report on Last Backup

Post by NK100251 »

Can we do the same for VMware and Nutanix AHV backup jobs?
rovshan.pashayev
Veeam Software
Posts: 443
Liked: 94 times
Joined: Jul 03, 2023 12:44 pm
Full Name: Rovshan Pashayev
Location: Czechia
Contact:

Re: PS to report on Last Backup

Post by rovshan.pashayev » 1 person likes this post

Hello,

You will need to adjust the $vms value, as the command for searching VMware objects differs from the command used for searching HyperV objects.

Find-VBRViEntity --- Looks for VMware entities created on a selected host.
Find-VBRHvEntity --- Returns Hyper-V objects added to Veeam Backup & Replication.

Rovshan.
Rovshan Pashayev
Analyst
Veeam Agent for Linux, Mac, AIX & Solaris
Deansbkk
Influencer
Posts: 18
Liked: never
Joined: Feb 23, 2010 6:13 am
Full Name: Dean S
Contact:

Re: PS to report on Last Backup

Post by Deansbkk »

Hello @rovshan.pashayev,

Thank you very much for this. I've tried to change your script (specifically focused on the IF statement) to INCLUDE the VM's without restore points as this is a key requirement for us. Would you mind editing your script one more time to include these?
rovshan.pashayev
Veeam Software
Posts: 443
Liked: 94 times
Joined: Jul 03, 2023 12:44 pm
Full Name: Rovshan Pashayev
Location: Czechia
Contact:

Re: PS to report on Last Backup

Post by rovshan.pashayev »

Hello @Deansbkk ,

Try to run following PS Script:

Code: Select all

$vms = Find-VBRHvEntity | where {$_.VmHostName -eq "your-example-hyperv-name" }
$AllMachinesReport = @() #initialize the array
$AllRPs = Get-VBRRestorePoint #We get all RPs here to avoid calling Get-VBRRestorePoint multiple times in the loop; this will take longer initially, but be way faster in the long run
foreach ($vm in $vms) 
{ 
    $restorePoint = $AllRPs | Where-Object{$_.VMName -eq $vm.Name} | Sort-Object -Property CreationTime -Descending | Select-Object -First 1
    $VMObject = [PSCustomObject]@{
         VM_Name =  $vm.Name.ToString()
         Last_Restore_point = if($restorePoint) {$restorePoint.CreationTime.ToString()} else {"No Restore Point"}
     }
    $AllMachinesReport += $VMObject
}
$AllMachinesReport | Export-CSV -NoTypeInformation C:\temp\output.csv; start C:\temp
It should give you list of all VMs with Last Resort Point date.
If there is no restore point, then "No Restore Point" text will be populated in the column.

Rovshan
Rovshan Pashayev
Analyst
Veeam Agent for Linux, Mac, AIX & Solaris
Deansbkk
Influencer
Posts: 18
Liked: never
Joined: Feb 23, 2010 6:13 am
Full Name: Dean S
Contact:

Re: PS to report on Last Backup

Post by Deansbkk »

Hello @rovshan.pashayev,

This works perfectly! Thank you very much.
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests