Solved

Parsing a file for a date

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

Are your corporate email signatures appalling?

Is it scary how unprofessional your email signatures look? Do users create their own terrible designs and give themselves stupid job titles? You can make this a lot easier for yourself by choosing an email signature management solution from Exclaimer today.

Join & Write a Comment

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…

758 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now