Solved

Parsing a file for a date

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

777 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