From monthly archives: July 2012

We are pleased to present below all posts archived in 'July 2012'. If you still can't find what you are looking for, try using the search box.

Timothy

PowerShell: Quickly Finding the Oldest and Newest Files in a Folder

I whipped up this script to quickly find the oldest and newest files in a folder with PowerShell because we have some archive folders that have millions of files and it can crash Windows Explorer.  Other scripts I’ve seen online use PowerShell’s Where-Object after doing a sort on the entire collection, but that’s inefficient because it requires sorting millions of file records, which is slow.  What I’m doing is using ForEach-Object to track the oldest and newest dates as I parse through the directory list in whatever order it comes to me.  It saves a lot of time and memory.  Enjoy!

$olddate = [DateTime]::MaxValue $newdate = [DateTime]::MinValue $oldfn = "" $newfn = "" $path = "." get-childitem $path | ForEach-Object { if ($_.LastWriteTime -lt $olddate -and -not $_.PSIsContainer) { $oldfn = $_.Name $olddate = $_.LastWriteTime } if ($_.LastWriteTime -gt $newdate -and -not $_.PSIsContainer) { $newfn = $_.Name $newdate = $_.LastWriteTime } } $output = "" if ($oldfn -ne "") { $output += "`nOldest: " + $olddate + " -- " + $oldfn } if ($newfn -ne "") { $output += "`nNewest: " + $newdate + " -- " + $newfn } if ($output -eq "") { $output += "`nFolder is empty." } $output + "`n"

Recent Comments
  1. Re: RD Tabs: Increased Memory Consumption with 2012+ Servers and Error 3334
    Mano: Happy wednesday wishes images wednesday sms wednesday pictures Happy wednesday wishes happy wednesday...
  2. Re: RD Tabs: Increased Memory Consumption with 2012+ Servers and Error 3334
    Mano: Happy wednesday wishes images wednesday sms wednesday pictures Happy wednesday wishes happy wednesday...
  3. Re: RD Tabs: Increased Memory Consumption with 2012+ Servers and Error 3334
    Mano: Happy wednesday wishes images wednesday sms wednesday pictures Happy wednesday wishes happy wednesday...
  4. Re: RD Tabs: Increased Memory Consumption with 2012+ Servers and Error 3334
    Mano: Happy wednesday wishes images wednesday sms wednesday pictures Happy wednesday wishes happy wednesday...
  5. Re: RD Tabs: Increased Memory Consumption with 2012+ Servers and Error 3334
    Mano: Happy wednesday wishes images wednesday sms wednesday pictures Happy wednesday wishes happy wednesday...
  6. Re: In VB.Net, sending output to the console from a Windows "Forms" application
    clochardM33: Glorious
  7. Re: DPM 2016 + SQL 2016 and "An unexpected error occurred during the installation" ID: 4387
    Andreas Hagberg: Edward, you are the man. It solved the problem right at the first try. Many thanks for the post.
  8. Re: DPM 2016 + SQL 2016 and "An unexpected error occurred during the installation" ID: 4387
    Andreas Hagberg: Edward, you are the man. It solved the problem right at the first try. Many thanks for the post.
  9. Re: DPM 2016 + SQL 2016 and "An unexpected error occurred during the installation" ID: 4387
    Andreas Hagberg: Edward, you are the man. It solved the problem right at the first try. Many thanks for the post.
  10. Re: DPM 2016 + SQL 2016 and "An unexpected error occurred during the installation" ID: 4387
    Derek: Edward, great find. +1 on the fix... Thanks!!