Solved

look for dates in a file not the last wrtten

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
This article will help you understand what HashTables are and how to use them in PowerShell.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

18 Experts available now in Live!

Get 1:1 Help Now