$SetFileNames = @() $TESTFiles | Sort-Object Directory, LastWriteTime, Name | Group-Object -Property {Get-Date $_.LastWriteTime -Format d } | ForEach-Object { $_.Group | ForEach-Object -Begin { $counter = 0 $FirstFile = $_ # Grab the files for each folder which are the first file of each day. $SetFileNames += $FirstFile.Group[0] } -Process { $counter++; # Do work here } } $SetFileNames