PowerTip: Find Files Modified During a Date Range by Using PowerShell

PowerTip: Find Files Modified During a Date Range by Using PowerShell

  • Comments 1
  • Likes

Summary: Use Windows PowerShell to find files that were modified during a specific date range.

Hey, Scripting Guy! Question How can I use Windows PowerShell to find all files modified during a specific date range?

Hey, Scripting Guy! Answer Use the Get-ChildItem cmdlet to collect the files, filter it to the Where-Object cmdlet, specify the date for the LastWriteTime property, and set greater than and less than parameters:

dir | ? {$_.lastwritetime -gt '6/1/13' -AND $_.lastwritetime -lt '6/11/13'}

Note   dir is an alias for the Get-ChildItem cmdlet, and the ? character is an alias for the Where-Object cmdlet. Windows PowerShell automatically converts ‘6/1/13’ into a date for this operation.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • This is my favorite Cmdlet.   It was the first one I really used in Windows Powershell.  Combined with a REMOVE-ITEM -what and the .adddays() method I was able to remove log files over 24 hours left behind by a vendor application.

    The reason I loved it?

    1. It was an easy to implement solution I found on "ScriptingGuys"

    2. the -WHATIF parameter allowed me to work without a Development environment available

    3. I got to go home early on a Friday with 15 minutes of work and 2 hours billed.

    4. I wrote a song called "Highway to Powershell" on the way home from this early day :)

    Sean "I <3 Powershell"