################################################## # # Written by Ian Cammarata # Get-HpProductInfo.ps1 v0.1 # ################################################## # # Usage: # Get-HpProductInfo < serial number > # Ex: # Get-HpProductInfo JPBCD3R1H3 # ################################################## # # Notes: # -Will probably only work for products sold in the US unless you change the country # codes in $hpWarrantyQueryURL and the $htClient.Headers.set(...Cookie... # # To Do: # -Make it a proper PowerShell script (receive piped input, input validation, multiple SNs at once) # -Cache objects to an XML file for faster loading if the same SN is queried again. # -Multi-threading the http downloads and multiple retry attemps (partsufer is so unreliable lately) # -Option to filter parts output # # SNs for testing: CND120CJH0, CNU305BP9N, CNFKF52058, JPBCD3R1H3 # ################################################## Set-StrictMode -Version Latest $lookupSn = "CND120CJH0" if ($args) { $lookupSn = $args[0] } $partSurferQueryUrl = "http://partsurfer.hp.com/Search.aspx?searchText=" $hpWarrantyQueryUrl = "http://h20000.www2.hp.com/bizsupport/TechSupport/WarrantyResults.jsp?lang=en&cc=us&country=US&find=Display+Warranty+Information+%C2%BB" ### Create WebClient and cookie needed for PartSurfer $htClient = New-Object System.Net.Webclient $htClient.Headers.Set([System.Net.HttpRequestHeader]::Cookie, "Country=United%20States") ### Download and clean PartSurfer HTML so it can be parsed into XML $ErrorActionPreference = "Stop" #Needed so script won't continue if the web server returns an error $htData = $htClient.DownloadString("$($partSurferQueryUrl)$($lookupSn)") $htData = -join $htData[$htData.IndexOf("
")+6)] $htData = $htData -replace '(?sx: