Solved

Parsing a file for a date

Posted on 2013-11-22
2
291 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

Industry Leaders: 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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

752 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