question

BastiaanOosterman-4075 avatar image
0 Votes"
BastiaanOosterman-4075 asked BastiaanOosterman-4075 commented

Create a Powershell script to automatically lookup and download HP printer firmware files

Hi,

I want to create a Powershell script that I can run periodically to automatically download the latest HP printer firmware files.

The source where I can find the path to the latest firmware file for each printer model is this URL:
http://ftp.ext.hp.com//pub/networking/software/pfirmware/pfirmware.glf

One item for example:

[HP LaserJet 600 M601/M602/M603]
SupportedModels = HP LaserJet M601n; HP LaserJet M601dn;HP LaserJet M602n; HP LaserJet M602dn; HP LaserJet M602x; HP LaserJet 600 M602;HP LaserJet M603n; HP LaserJet M603dn; HP LaserJet M603xh; HP LaserJet 600 M602; HP LaserJet 600 M603; HP LaserJet 600 M601;
Path = http://ftp.hp.com/pub/networking/software/pfirmware/ljM601_602_603_fs3.9.9_2309059_000599.bdl
Name = ljM601_602_603_fs3.9.9_2309059_000599.bdl
Size = 86072636
Version = 2309059_000599 (FutureSmart Bundle Version 3.9.9)
Revision = 2309059_000599
Date = 20220214
Asset Identifier = 736664-0015

I would like the script to download the firmware of some printer models that I can specify beforehand, so I don't need all the firmware files.

Unfortunately I don't have much knowledge of how to create Powershell script, so I hope someone has an example for me similar to this that I can reuse.

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered BastiaanOosterman-4075 commented

This should work:

 $desiredmodels = "HP Color LaserJet 2605","HP LaserJet 3050 AIO","SL-K4350LX"
 $OutputDirectory = "c:\junk\"
 [array]$Downloads = @()
    
 $x=Invoke-WebRequest http://ftp.ext.hp.com//pub/networking/software/pfirmware/pfirmware.glf
    
 $inaprinter = $false
 $info= @{}
    
 ForEach ($l in ($x.content -split ("`r`n"))) {
     ForEach-Object{
         if ($l.Trim().Length -lt 1){
             Continue                    # skip empty lines
         }
         if ($l.substring(0,2) -eq ";;"){
             # do nothing, it's just a comment
             Continue
         }
            
         if ($l.substring(0,1) -eq "["){ # the start of a new printer data set
             if ($inaprinter -and $info['download'] -eq $true){  # if there's a completed record, save it
                 $Downloads += [PSCustomObject]$info
             }
             $inaprinter = $true
             $info.clear()
             $info['download'] = $false
             Continue                        # not interested in the name, just the fact that it's the beginning
         }
         $l = $l -replace " \t+="," ="            # some data sets place tabs immediately before the '='! Remove them.
         [array]$p = $l -split " = "
         if ($p.count -ne 2){        # only interested in lines like X = Y
             Continue
         }
         switch ($p[0]) {
             "SupportedModels" {
                 [array]$models = $p[1].split(";",[System.StringSplitOptions]::RemoveEmptyEntries)
                 if ($models.count -gt 0){
                     ForEach ($model in $models){
                         if ($desiredmodels -contains $model){
                             $info['download'] = $true
                         }
                     }
                 }
                 break
             }
             "Path" {$info[$p[0]] = $p[1]; break}
             "Name" {$info[$p[0]] = $p[1]; break}
         }
     }
 }
 if ($inaprinter -and $info['download'] -eq $true){  # in case there's pending record
     $Downloads += [PSCustomObject]$info
 }
 $Downloads |
     ForEach-Object{
         Invoke-WebRequest -Uri $_.Path -OutFile "$OutputDirectory$($_.Name)"
     }
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Wow, thank you very much! This is exactly what I was looking for.

0 Votes 0 ·