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
@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.
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.
$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
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.
$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
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
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?
$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