Unable to filter collection of objects to select only those with latest date
Group the files by their full name, then select the most recent file from each group:
$restoreItems | Group-Object FullName | ForEach-Object { $_.Group | Sort-Object DeletedDate | Select-Object -Last 1}
This assumes that the timestamp is a DateTime
object. Should it actually be a string you need to parse it to a DateTime
object first, as LotPings pointed out in the comments, otherwise the sort order won't be correct.
I'm guessing $items is a PowerShell Object and the blurred out information contains the same strings. You could try:
$items | Sort-Object -Property DeletedDate,Name -Unique
If the order is not right, try
$items | Sort-Object -Property DeletedDate,Name -Unique -Descending
Basically you just need to sort on two properties, and then select the unique values.