#
.NOTES
Written by Ian Cammarata http://ian.cammarata.us
Get-HpProductInfo.ps1 v0.10
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:
-Multi-threading the http downloads and multiple retry attemps (partsufer is so unreliable lately)
-Generate a proper object (this will allow tab completion and easier programmatic use)
SNs for testing: CND120CJH0, CNU305BP9N, CNFKF52058, JPBCD3R1H3, CNU349BDTD
.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, ValueFromPipeline= $True )]
[Alias( "SN" )]
[String[]]
$SerialNumber,
#Search string for parts listing.
[Parameter( Position = 1 )]
[Alias( "Part" )]
$PartQuery,
#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
)
BEGIN {
Set-StrictMode -Version Latest
IF ( $Script:PSBoundParameters.ContainsKey("Debug") ) { $DebugPreference = "Continue" } ### For some reason I was getting first 3 debug lines output in the Process block even with using -Debug, but none afterwards
###### Set Constants
IF ( -not ( Test-Path Variable:\\fullRegionName ) ) { #This prevents errors from being generated when running from ISE
Set-Variable fullRegionName -Option Constant -value "United States"
Set-Variable abbrRegionName -Option Constant -Value "US"
Set-Variable regionSuffix -Option Constant -Value "#ABA"
Set-Variable ForeignPartSuffixes -Option Constant -Value "-031|-041|-051|-061|-071|-081|-091|-131|-141|-161|-171|-201|-211|-251|-261|-271|-281|-291|-A41|-AB1|-AD1|-B31|-B71|-BA1|-BB1|-BG1|-D61|-DB1|-DD1|-DJ1|-FL1"
Set-Variable OtherPartRejectionStrings -Option Constant -value "no longer supplied|Not Available|Hebrew|Cyrillic|Greek|Arabic|Bulk|220V|- AR|- CS|- DA|- NL|- FI|- DE|- EL|- HE|- HU|- KO|- NO|- PL|- ZHCN|- ZHTW|- TH|PCID|SWID| CH | CH<|CHINARUSS"
Set-Variable productObjectVersion -option Constant -value 0.4
Set-Variable partSurferQueryUrl -option Constant -value "http://partsurfer.hp.com/Search.aspx?searchText="
Set-Variable hpWarrantyBaseUrl -option Constant -value "https://h20565.www2.hp.com"
Set-Variable hpWarrantyStartPath -option Constant -value "/portal/site/hpsc/public/wc/home/"
Set-Variable hpWarrantyQueryUrl -option Constant -value "https://h20566.www2.hp.com/portal/site/hpsc/template.PAGE/action.process/public/wc/home/?javax.portlet.action=true&javax.portlet.sync=d549c6d9a9acda7f8405adb432a15c01&javax.portlet.tpst=c4efedb99acca32ea782977bb053ce01&javax.portlet.prp_c4efedb99acca32ea782977bb053ce01=wsrp-interactionState%3Daction%253Dfind&javax.portlet.begCacheTok=com.vignette.cachetoken&javax.portlet.endCacheTok=com.vignette.cachetoken"
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 }
### This was causing issues with other PowerShell scripts. It will remain disabled till I learn to fix it across all versions of PowerShell or I no longer need to support PS 1.0.
<# ###### Default display property set #Maybe this will be added back in future, not really necessary anyway
$objectTemplateFile = Join-Path $cacheDir "HpProductObjectTemplate_v$($productObjectVersion).ps1xml"
IF ( !( Test-Path $objectTemplateFile ) ) {
$template = ""
$template += "