Submit the form and get warranty details using Invoke-WebRequest

It is my first post so greetings to everyone

I am a beginner in PowerShell. I begin to like it.

My goal is to check the warranty status using webpage.

I am trying to submit Serial number and Product Number to HP site in order to check the warranty status.

I tried to follow the example from [url]http://technet.microsoft.com/library/3e3dac17-3373-4d22-a54a-9d56a4a556c3(v=wps.630).aspx[/url]

My code is follow

{
#if you do not have HP model use this hardcoded values for testing
#$sn = 4CZ1232NN7;$pn = XU063UT#ABA 

#Get serial and product number

$SN = (Get-WmiObject win32_bios).SerialNumber                                                                                           
$PN = Get-WmiObject HP_BIOSSetting -Namespace "root\HP\InstrumentedBIOS" -Filter "Name = 'Product Number'" | Select -ExpandProperty value

$r = Invoke-WebRequest http://h10025.www1.hp.com/ewfrf/wc/weInput?cc=us"&"lc=en -SessionVariable hp

$form =$r.Forms[1]
$form.Fields["serialnum"]=$sn  
$form.Fields["prodName"]=$pn

$result=Invoke-WebRequest -Uri ("http://h10025.www1.hp.com/ewfrf/wc/" + $form.Action) -WebSession $hp -Method POST -Body $form.Fields
#$result.RawContent | Out-File -FilePath .\hp.html
}

Thank you.

Hi Tomasz,

Welcome to the PowerShell.org forums. For your next post please explain what is not working and what kind of help you’re looking for.

Please check if below code works for you:

Param
(
    [String]$SerialNumber = 'HU265BM18V',
    [String]$ProductNumber = 'H1P31AA'
)
 
$fields = @(
    'tmp_weCountry=us',
    "tmp_weSerial=$SerialNumber",
    "tmp_weProduct=$ProductNumber",
    "product=",
    "lc=en",
    "dlc=en"
    "cc=us"
)
 
$result=Invoke-WebRequest -Uri 'http://h10025.www1.hp.com/ewfrf/wc/weResults' -Method POST -Body ($fields -join '&')
$result.RawContent | Out-File -FilePath C:\Temp\hp.html | & 'C:\Program Files\Internet Explorer\iexplore.exe' C:\Temp\hp.html

Best,
Daniel

Hi Daniel,

Thank you for the reply. Your code works for me. I like the way you used ‘-join’ operator to pass all argurments.
Finally to obtain the clean values I processed the object in the following way. If there is a more efficient way I will be greatfull to know.

Param
(
    [String]$SerialNumber = 'HU265BM18V',
    [String]$ProductNumber = 'H1P31AA'
)
 
$fields = @(
    'tmp_weCountry=us',
    "tmp_weSerial=$SerialNumber",
    "tmp_weProduct=$ProductNumber",
    "product=",
    "lc=en",
    "dlc=en"
    "cc=us"
)
 
$result=Invoke-WebRequest -Uri 'http://h10025.www1.hp.com/ewfrf/wc/weResults' -Method POST -Body ($fields -join '&')
$xmlresult = $result.AllElements | select -ExpandProperty innertext -Unique | ConvertTo-Xml
$WarrantyStatus = ($xmlresult.Objects.Object | where  `#text -Like "Warranty status*Warranty").'#text'.substring(15) 
$WarrantyEndDate = ($xmlresult.Objects.Object | where  `#text -Like "Warranty end date*(YYYY-MM-DD)").'#text'.substring(17,10)
Out-Default -InputObject "Warranty status: $WarrantyStatus. Warranty end date: $WarrantyEndDate"


    

This check is ok for single local machine. At work I have tousands of pcs already inventored with Serial Number.in database.
In the end I’like to be able to proces the requests in batches.
This page allows to submit up to 20 serial numbers and does not require the product number.
http://h20566.www2.hp.com/portal/site/hpsc/public/wc/home?ac.admitted=1405798585213.876444892.199480143
Since I am new in the forum, could you advise : should I open a new thread if I need further help ?

Thank you.
Tomasz

Tomasz,

Getting warranty information via the HP websites is kind of tricky. Scraping the web sites and posting forms does not really work for a long time and the >20 serial number page throws in a Captcha check after the 2-3 query to make things even more interesting.

HP provides a web API call ISEE for programmatic checks. Links to get you started:

https://powershell.org/forums/topic/invoke-webrequest-powershell-2-0/
https://powershell.org/forums/topic/getting-hp-warranty-information/

http://stackoverflow.com/questions/24058731/powershell-trying-to-check-warranty