Solved

how to retrieve files of a specific date

Posted on 2016-07-27
5
58 Views
Last Modified: 2016-07-28
Hi I'm trying to list all files which have been modified on a specific date.  I would have thought this would be quite a simple and common task in powershell but as always...

I have come up with the following code but unfortunately it doesn't return anything even though I know there are files there with that last write time

Get-ChildItem "C:\Users\jsmith" | Where-Object {$_.LastWriteTime.Date -eq "17/05/2016"} | ForEach-Object {$_.FullName, $_.LastWriteTime}

Open in new window

0
Comment
Question by:carbonbase
5 Comments
 
LVL 84

Assisted Solution

by:oBdA
oBdA earned 125 total points
ID: 41731269
Should work (it does for me), provided your date format is correct.
Could it be that you forgot the -recurse switch for Get-ChildItem? You're only looking in the root of "C:\Users\jsmith".
0
 
LVL 54

Assisted Solution

by:Bill Prew
Bill Prew earned 125 total points
ID: 41731273
Works okay here, once I adjust the date format, is that correct for your system?

Also, keep in mind folders in that base directory will be shown as well if they were last changed on that date, not sure if you want that or just files?

Also, you are only looking in the root folder you specified, you would need to add -recurse to drill into subfolders.

~bp
0
 
LVL 45

Accepted Solution

by:
aikimark earned 250 total points
ID: 41731958
As Bill Prew hinted, you need to use mm/dd/yyyy formatted dates or a date object
0
 

Author Closing Comment

by:carbonbase
ID: 41732829
Thanks for your comments guys.  So in the code I need to specify the date in US date format, even though the results display in my localised (UK) date format.
0
 

Author Comment

by:carbonbase
ID: 41732834
So for reference my code now looks like this:

 Get-ChildItem -Recurse "C:\Users\jsmith" | Where-Object {!($_.PSIsContainer)} | Where-Object {$_.LastWriteTime.Date -eq "05/17/2016"} | ForEach-Object {$_.FullName, $_.LastWriteTime}

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question