Solved

Parsing a file for a date

Posted on 2013-11-22
2
294 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
[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 500 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

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

A small collection of useful tips and tricks for Windows 10 users that I decided to write as a result of recent questions that were asked and answered at Experts Exchange. Two short video tutorials included. Enjoy..
Windows 10 Creator Update has just been released and I have it working very well on my laptop. Read below for issues, fixes and ideas.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
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…

628 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