#
.NOTES
Written by Ian Cammarata http://ian.cammarata.us
Get-HpProductInfo.ps1 v0.2
This will probably only work for products sold in the U.S. 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
.SYNOPSIS
Query by SN to retreive HP product info from PartSufer and HP Business warranty lookup.
.EXAMPLE
PS> Get-HpProductInfo JPBCD3R1H3
#>
param(
#The serial number to query.
[Parameter( Mandatory = $True, Position = 0 )]
[Alias( "SN" )]
[String]
$SerialNumber,
#Output an object instead of an plain text.
[Switch]
[Alias( "Object" )]
$OutputObject,
#Purge cash for supplied SN(s) and fetch fresh data
[Switch]
[Alias( "Purge" )]
$Refresh
)
### Being Setup
Set-StrictMode -Version Latest
###### Set Constants
#<# ### uncomment this line for testing in ISE after initial run
Set-Variable productObjectVersion -option Constant -value 0.2
Set-Variable partSurferQueryUrl -option Constant -value "http://partsurfer.hp.com/Search.aspx?searchText="
Set-Variable hpWarrantyQueryUrl -option Constant -value "http://h20000.www2.hp.com/bizsupport/TechSupport/WarrantyResults.jsp?lang=en&cc=us&country=US&find=Display+Warranty+Information+%C2%BB"
Set-Variable cacheDir -option Constant -value (Join-Path $env:APPDATA "HpProductInfo_Cache")
Set-Variable maxCacheAge -option Constant -value 90 #In Days
#>
###### Prep
if ( !( Test-Path $cacheDir ) ){ $null = New-Item -Type "Directory" -Path $cacheDir }
###### Default display property set
$objectTemplateFile = Join-Path $cacheDir "HpProductObjectTemplate_v$($productObjectVersion).ps1xml"
if ( !( Test-Path $objectTemplateFile ) ) {
$template = ""
$template += "