#
.NOTES
Written by Ian Cammarata http://ian.cammarata.us
Get-HpProductInfo.ps1 v0.9
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)
-Filter out more irrelevant parts by country code suffix on the PN. ex: -BG1 = Swiss
-Fix: When there are multiple matching products, it will output a bunch of errors on the first query for that serial number. Subsequent queries will pull data that was cached and will display fine.
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, 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 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 += "