Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

look for dates in a file not the last wrtten

Posted on 2016-09-20
2
Medium Priority
?
45 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

722 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