[PowerShell] / Get-HpProductInfo.ps1 Repository:
ViewVC logotype

View of /Get-HpProductInfo.ps1

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9 - (download) (annotate)
Sun Aug 18 00:07:30 2013 UTC (10 years, 8 months ago) by ian
File size: 5978 byte(s)
Now sending cookie with country set to US so the server provides check boxes indicating orderable parts;
Filtering orderable parts by check box and then by -001 suffix;
þÿSet-StrictMode -Version Latest

$ErrorActionPreference = "Stop" #Needed so script won't continue if the web server returns an error



$lookupSn = "CND120CJH0"

if ($args) { $lookupSn = $args[0] }



#SNs to test with CND120CJH0, CNU305BP9N



$partSurferQueryUrl = "http://partsurfer.hp.com/Search.aspx?searchText="

$htClient = New-Object System.Net.Webclient

#Cookie ||| Name: country - Content: United%20States - host: partsufer.hp.com - Path: /

$htClient.Headers.Set([System.Net.HttpRequestHeader]::Cookie, "Country=United%20States")



$htData = $htClient.DownloadString("$($partSurferQueryUrl)$($lookupSn)")



#Clean HTML so it can be parsed into XML

$htData = -join $htData[$htData.IndexOf("<body")..($htData.LastIndexOf("</body>")+6)]

$htData = $htData -replace '(?sx:<script[\s\S]*?</script[\s\S]*?>)'

$htData = $htData -replace '(?sx:<noscript[\s\S]*?</noscript[\s\S]*?>)'

$htData = $htData -replace ' & ', " and "

$htData = $htData -replace "&\w{2,6};"

<#  will parse without these cleanup steps

$htData = $htdata -replace '^\s+$', " "

$htData = $htData -replace '<!Doctype[\s\S]*?>'

$htData = $htData -replace '(?sx:<option[\s\S]*?</option[\s\S]*?>)'

$htData = $htData -replace '(?sx:<!--[\s\S]*?-->)'

$htData = $htData -replace '(?sx:<input[\s\S]*?/>)'

end unused cleanup #>

$partSurferXml = [xml]$htData



$ErrorActionPreference = "SilentlyContinue" #Needed so filtering by ID won't generate an error on nodes with no ID property

#Parse SN, Sku, and Description from XML

$skuXmlObjects = $partSurferXml.SelectNodes("//span") | ? { $_.id -like "*lbl*" -and $_.id -notlike "*BOM*" -and $_.id -notlike "*text*" }

#Parse Parts from XML

$partXmlObjects = $partSurferXml.SelectNodes("//span") | ? { $_.id -like "*BOM*part*" -and $_.'#text' -notlike "*N/A*" }

#Get collection of input:checkboxes to match against to determine if part is orderable

$orderCheckboxXmlObjects = $partSurferXml.SelectNodes("//input") | ? { $_.id -like "*chkSpareBOM" }

$ErrorActionPreference = "Continue"



#Parse orderable U.S. parts from XML

$orderableParts = @()

foreach ( $part in ( $partXmlObjects | ? { $_.id -like "*lblspart1" } ) ) {

    if ( $part.id -match ".*(_ctl\d{2,3}_).*" ) {

        if ( $orderCheckboxXmlObjects | ? { $_.id -like "*$($matches[1])*" } ) {

        $newPart = ($partXmlObjects | ? { $_.id -like "*$($matches[1])*" -and $_.id -notlike "*Enhanced" } | % { $_.'#text' }) -join "`t"

        #$partText = $partXmlObjects | ? { $_.id -like "*$($matches[1])*" -and $_.id -notlike "*Enhanced" } | % { $_.'#text' }   

        #$newPart = $partText -join "`t"            

        if( $newPart -like "*-001*" ) { $orderableParts += $newPart }

        }

    }

}



#Display data

"-"*90

($skuXmlObjects | ?{$_.id -like "*SerialNumber"}).'#text'

($skuXmlObjects | ?{$_.id -like "*ProductNumber"}).'#text'

($skuXmlObjects | ?{$_.id -like "*Description"}).'#text'

""

"Available Parts: $($orderableParts.Length)"

"-"*90

$orderableParts

"-"*90

Contact
ViewVC Help
Powered by ViewVC 1.0.4