0

I have written a little script to get the creation time of each restore point in the last x days:

$VMs = $ImportCSV  # Names of Virtual Machines 
$DateToCompare = 10
foreach ($vm in $VMs) {
    $allRestorePoints = Get-VBRRestorePoint -Name $vm.Name |
                        where {$_.CreationTime -gt $DateToCompare} |
                        Select-Object VMName, CreationTime 
}

This script is showing me all the VM names and the creation time of the restore points in the last $DateToCompare days. But how can I count the restore points for each VM and export it to CSV?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328

1 Answers1

1

With the code you posted you will have only the restore points of the last VM in $VMs in the variable $allRestorePoints.

To get the restore point count for all VMs enumerate all restore points for all VMs and group by VM name:

$restorePoints = $VMs | ForEach-Object {
    Get-VBRRestorePoint -Name $_.Name |
        Where-Object { $_.CreationTime -gt $DateToCompare }
} | Select-Object VMName, CreationTime

$restorePoints |
    Group-Object VMName |
    Select-Object Name, Count |
    Export-Csv 'C:\output.csv' -NoType
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328