Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Parsing a file for a date

Posted on 2013-11-22
2
Medium Priority
?
302 Views
Last Modified: 2013-11-22
A powershell Noob,

I'm trying to parse a webpage to pull the expiration date of the equipment.  

Process so far:

1.

Powershell Script goes out and Queries each machine on the network and gets the following: Serial Number, Model, User

2.

copies the information to a comma separated text file

3.

queries lenovo website to get the warranty expiration date
I'm trying to use the HTML temp file to parse the expiration date.  All I want is the expiration date from the file, but because the literal expression is "<td valign="top" width="120">2015-10-20</td><td valign="top" width="4">" with the expiration date being "2015-10-20" I'm unable to get that information.

I can't do a query for the exact match because as mentioned it's several machines.  Once I can complete the query I can output the data to a text file, I just can't figure out how to format the query.

The temp HTML file is attached.

Thanks in advance

Eric
WarrantyLookup.txt
0
Comment
Question by:erobby
2 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 total points
ID: 39670157
Try this and see if you get the correct Warranty information..
$Value = GC C:\WarrantyLookup.txt | 
	Select-String -Pattern `
	"(Expiration\sdate:).*(20\d\d\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01]))"`
| % {$_.Matches | Select -ExpandProperty groups }

$Value[2].Captures[0].Value

Open in new window

BTB, Expression "\d{4}\-\d{2}\-\d{2}" or "20\d{2}\-\d{2}\-\d{2}" will also match the date format, However it will also match values like 2099-99-99. But in your case we are not expecting such values in the webpage so it may work..

"20\d\d\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])" will give you the exact match for date format..
0
 
LVL 2

Author Closing Comment

by:erobby
ID: 39670271
Subsun,

Thanks I just need to tweak it now for my script.
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

Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
Loops Section Overview

879 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