Solved

look for dates in a file not the last wrtten

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
Synchronize a new Active Directory domain with an existing Office 365 tenant
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.

820 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