Solved

look for dates in a file not the last wrtten

Posted on 2016-09-20
2
32 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

861 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now