Solved

look for dates in a file not the last wrtten

Posted on 2016-09-20
2
35 Views
Last Modified: 2016-09-20
i need it to  look for the date on the file instead of the last written file..

here is a example of a file that it will serach for:
file naming convention yyyy_mm_dd.html (ex. "2016_09_16.html")
file naming convention logfile_yyyy_mm_dd.html (ex. "logfile_2016_09_14.html")

Code:
$att1 = Get-ChildItem E:\Extranet\batchProcess\logs -Filter *.html | Sort-Object -Property LastWriteTime -Descending | Select-Object -First 1 -ExpandProperty FullName
0
Comment
Question by:eperez0968
2 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 41806602
If you want to sort the files based on the date on file name.. Try..
Get-ChildItem E:\Extranet\batchProcess\logs -Filter *.html |?{$_.Name -match "(\d{4})_(\d{2})_(\d{2})"} | Select FullName,LastWriteTime,@{N="FileTime";E={[datetime]"$($Matches[2])/$($Matches[3])/$($Matches[1])"}} | Sort FileTime -Descending  | Select-Object -First 1 -ExpandProperty FullName

Open in new window

Or
Get-ChildItem E:\Extranet\batchProcess\logs -Filter *.html |?{$_.Name -match "(\d{4})_(\d{2})_(\d{2})"} | Select FullName,LastWriteTime,@{N="FileTime";E={[datetime]($Matches[0] -replace "_","/")}} | Sort FileTime -Descending  | Select-Object -First 1 -ExpandProperty FullName

Open in new window

0
 

Author Closing Comment

by:eperez0968
ID: 41806690
worked like a charm thanks
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
A brief introduction to what I consider to be the best editor for PowerShell.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

785 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