mercoledì 22 maggio 2019

Multiple models , how to download drivers (HP softpaqs) using Powershell script

As usual you need HP Client Management (Powershell) Script Library available here https://ftp.hp.com/pub/caps-softpaq/cmit/hp-cmsl.html

download and install them on the PC where you want to download softpaqs

my idea is to create a main folder , such as C:\SoftpaqRepository1.2

then a folder where to save all softpaqs of several models , for the same OS version.  in my case I created C:\SoftpaqRepository1.2\win10_1809

you must intialize the folder as a Softpaq Repository:
cd C:\SoftpaqRepository1.2\win10_1809
initialize-repository

no need to initialize anymore win10_1809 folder in the future.

in this folders I will download softpaq for several models, I got more than 600 softpaqs with my models list.


My script "Synchronize_repository1.2.ps1" does these steps:

First phase: creation of repository.json file

  1. create an array containing modesl list and its sys ID , ex ("840G5_1809","83b2"), ( I have 50 lines )
  2. cd C:\SoftpaqRepository1.2\win10_1809
  3. Add-RepositorySyncFailureRecipient
  4. Set-RepositoryNotificationConfiguration 
  5. using a loop , for each model in the array add a filter for Windows 10 1809 , for all softpaq categories: Add-RepositoryFilter -platform $sysid -os win10  -osver 1809
Second Phase: download all softpaq for all models listed in the array. It could take minutes or hours
  1. Invoke-RepositorySync 

finally  hundreds spxxxx.exe and spxxxx.cva file are saved in "C:\SoftpaqRepository1.2\win10_1809"

PS script creates a  win10_1809_backup folder too. files are not copied but hardlinked using ln.exe
Download lx.exe from http://schinagl.priv.at/nt/ln/ln.html and save it into C:\SoftpaqRepository1.2

download also Gawk.exe from https://sourceforge.net/projects/gnuwin32/files/gawk/3.1.6-1/gawk-3.1.6-1-setup.exe/download?use_mirror=datapacket&download=

copy gawk.exe to "C:\SoftpaqRepository1.2\win10_1809"

Third Phase: for each model in the array , script does an hardlink copy of all softpaqs in a folder named as the model string defined in the array.

as  "C:\SoftpaqRepository1.2\win10_1809" folder , in my case contains 80GB of data, instead of copying the files I use hardlink. this is fundamental otherwise your storage will run out of space very quickly.
  • "C:\SoftpaqRepository1.2\win10_1809\Models" is created
  • scripts create a folder for each model .  Folder will be labeled using model name written in the array ( "C:\SoftpaqRepository1.2\win10_1809\Models\840G5_1809")
  • creates hardlink of all files from win10_1809 to new folder (ex Models\840G5_1809) 
  • create a repository.json for this specific model in the model folder ("C:\SoftpaqRepository1.2\win10_1809\Models\840G5_1809\.repository\repository.json")

    "Filters":  [
                    {
                        "platform":  "83b2",
                        "operatingSystem":  "win10:1809",
                        "category":  "*",
                        "releaseType":  "*",
                        "characteristic":  "*"                    }
                ],
    "Notifications":  {
                          "server":  null,
                          "port":  25,
                          "tls":  false,
                          "addresses":  null,
                          "username":  "",
                          "password":  "",
                          "from":  "softpaq-repo-sync@xxxxx.com",
                          "fromname":  "Softpaq Repository Notification"
                      }
  • as C:\SoftpaqRepository1.2\win10_1809\Models\840G5_1809\.repository\repository.json  contains only the sysID for this model (see above) , script executes cd C:\SoftpaqRepository1.2\win10_1809\Models\840G5_1809\ , then Invoke-RepositorySync
  • Invoke-RepositorySync will read repository.json , then removes all softpaq not matching filters found. It means all softpaqs not compatible with 840G5 will be deleted from the folder. You will have in 840G5_1809 only softpaqs compatible with this model.
  • go to next model in the array

NOTE: running Invoke-RepositorySync for each model , means that it will take a long time.So I modified HP scripts to save hours in downloading time. see my next post

example of what you will get

Step four : in each model folder , split the softpaq by category 

I had the need to split the softpaqs available in the model folder in categories.
again using a loop, for each model folder I do something similar to third step.

this is what you get , for example in "C:\SoftpaqRepository1.2\win10_1809\Models\840G5_1809\"


HP script just support 5 categories (version 1.2) : BIOS, driver, firmware, os, software. I modifyed script to accept also : diagnostic, utility and manageability


inside "C:\SoftpaqRepository1.2\Models\840G5_1809\bios" you will find only BIOS files




in "C:\SoftpaqRepository1.2\Models\840G5_1809\driver" folder you will find more softpaq



these will happens for every model included in the array.

script "Synchronize_repository1.2.ps1" :
$StartingFolder = "C:\SoftpaqRepository1.2"

cd $StartingFolder

import-module $StartingFolder"\HP.Softpaq.Shared.psm1"
import-module $StartingFolder"\HP.SoftpaqFC1.2.psm1"
import-module $StartingFolder"\HP.RepoFC1.2.psm1"

# check if a file exists
function fileExists ($file)
{
  Test-Path $file -PathType Leaf

}
$activityFile = $StartingFolder+"\win10_1809\.repository\activity.log"
if (fileExists ($activityFile) -EQ $true) {del $activityFile}
<#
comment , just in case
#>

[string[][]]$HPcomputer = @(

("X2_612_G2_1809","828b"), 
("X2_1012_G2_1809","82CA"),
("X2_1013_G3_1809","8414"),
("1030G2_1809","827D"),
("1030G3_1809","8438" ),
("1040G3_1809","80FA"),
("1040G4_1809","8417"),
("1040G5_1809","8470"),
("1050G1_1809","84E9"),
("840G3_1809","8079"),
("830G5_1809","83b3"),
("840rG4_1809","8418"),
("640G2_1809","80FD"),
("640G4_1809","83d2"),
("X360_440G1_1809","84D8"),
("430G6_1809","8536"),
("440G6_1809","8537"),
("450G6_1809","8538"),
("EliteOne1000G2_1809","83E5"),
("800G4_DM_83E2_1809","83E2"),
("800G4_DM_GPU_83E2_1809","83E2"),
("800G4_DM_8409_1809","8409"),
("800G4_DM_845A1809","845A"),
("EliteDesk800G4_TWR_1809","83E0"),
("EliteDesk800G4_AIO_83E3_1809","83E3"),
("EliteDesk800G4_AIO_83E4_1809","83E4"),
("EliteDesk800G4_SFF_1809","83E1"),
("EliteDesk705G4_SFF_83E8_1809","83E8"),
("EliteDesk705G4_SFF_8462_1809","8462"),
("EliteDesk705G4_SFF_8463_1809","8463"),
("EliteDesk705G4_MT_83E7_1809","83E7"),
("EliteDesk705G4_MT_8460_1809","8460"),
("EliteDesk705G4_MT_8461_1809","8461"),
("EliteDesk705G4_DM_83E9_1809","83E9"),
("EliteDesk705G4_DM_8464_1809","8464"),
("ProDesk600G4_MT_83EC_1809","83EC"),
("ProDesk600G4_MT_PCI_83ED_1809","83ED"),
("ProDesk600G4_MT_8580_1809","8580"),
("ProDesk600G4_SFF_1809","83EE"),
("ProDesk600G4_DM_1809","83EF"),
("EliteDesk600G4_AIO_83EA_1809","83EA"),
("EliteDesk600G4_AIO_83EB_1809","83EB"),
("ProDesk400G5_MT_83F0_1809","83F0"),
("ProDesk400G5_MT_83F1_1809","83F1"),
("ProDesk400G5_SFF_1809","83F2"),
("ProDesk400G4_DM_1809","83F3"),
("EliteDesk400G4_AIO_83EA_1809","83EA"),
("EliteDesk400G4_AIO_83EB_1809","83EB"),
("HP ZBook 15 G3 Mobile Workstation","80d5"),
("645G3_1809","823a"), 
("645G4_1809","8401"),
("840G5_1809","83b2"),
("735G5_1809","83da"),
("745G5_1809","83d5"),
("650G4_1809","8416"),
("650HG4_1809","844A"),
("HP ZBook 15 G5_1809","842A")
)

# this section populate and update the C:\SoftpaqRepository1.2\win10_1809 with softpaq .exe and .cva
cd $StartingFolder"\win10_1809"

del .\.repository\repository.json
copy ..\empty_repository.json .\.repository\repository.json
Set-RepositoryNotificationConfiguration -server "smtp.your_company.com" -username name.surname@hp.com  -password "Windows_password" -from "softpaq-repo-sync@your_company.com" -fromname "SOFTPAQ REPOSITORY NOTIFICATION" 
Add-RepositorySyncFailureRecipient -to name.surname@your_company.com 

foreach ($elemento in $HPComputer) {
$modello = $elemento[0]
$sysid = $elemento[1]
write-host 'adding model' $modello $sysid
Add-RepositoryFilter -platform $sysid -os win10  -osver 1809
}


write-host 'starting repository sync' -backgroundColor Yellow -ForegroundColor Black
Invoke-RepositorySync 

& $StartingFolder"\gawk.exe" -f $StartingFolder\awk_script_deviceID_softpaq.txt *.cva > all_Devices_softpaq.txt
& $StartingFolder"\gawk.exe" -f $StartingFolder\awk_script.txt *.cva > list_all_softpaq.txt

$lnexe = $($StartingFolder)+"\ln.exe"

$store = $($StartingFolder)+"\win10_1809"
$storebackup = $($StartingFolder)+"\win10_1809_backup"

# below line start ln.exe to make a backup of all softpaq via hardlink
& $lnexe "--recursive" $store  $storebackup

#Invoke-RepositoryCleanup

& $StartingFolder"\gawk.exe" -f $StartingFolder\awk_script_deviceID_softpaq.txt *.cva > all_Devices_softpaq.txt
& $StartingFolder"\gawk.exe" -f $StartingFolder\awk_script.txt *.cva > list_all_softpaq.txt


#this section separate the softpaq per model
foreach ($elemento in $HPComputer) {
$modello = $elemento[0]
$sysid = $elemento[1]
$CartellaModello = $StartingFolder+"\Models\"+$modello
$Cartellacontuttiisoftpaq = $StartingFolder+"\win10_1809"

cd $Cartellacontuttiisoftpaq

# hardlink copy all softpaq from $Cartellacontuttiisoftpaq to a folder label as the computer model string. 
# it will happens for his model in the array above


& $lnexe "--recursive" $Cartellacontuttiisoftpaq $CartellaModello
cd $CartellaModello
del .\.repository\repository.json
copy $StartingFolder"\empty_repository.json" .\.repository\repository.json
Add-RepositoryFilter -platform $sysid -os win10  -osver 1809
write-host 'working on ' $modello 
Invoke-RepositorySync
sleep 1
Invoke-RepositoryCleanup
Invoke-RepositoryCleanup
$file_lista = "lista_"+$modello+".txt"
& $StartingFolder"\gawk.exe" -f $StartingFolder"\awk_script.txt" *.cva > $file_lista
$escludecartella = "*"+$modello+"*"


cd ..

[string[]]$HPCategory = @(
("bios"), 
("driver"),
("firmware"), 
("software"),
("os")
("manageability")
("diagnostic")
("utility")
)

        foreach ($elemento in $HPCategory) {
        $categoria = $elemento
        $NuovaCartellaCategory = $CartellaModello+"\"+$categoria
        & $lnexe "--recursive" $Cartellacontuttiisoftpaq $NuovaCartellaCategory
        cd $NuovaCartellaCategory
        del .\.repository\repository.json
        copy $StartingFolder"\empty_repository.json" .\.repository\repository.json
        Add-RepositoryFilter -platform $sysid -os win10  -osver 1809 -category $categoria
        write-host 'working on ' $modello $categoria
Invoke-RepositorySync
        sleep 1
        Invoke-RepositoryCleanup
        Invoke-RepositoryCleanup
        $file_lista = "lista"+$modello+"_"+$categoria+".txt"
        & $StartingFolder"\gawk.exe" -f $StartingFolder"\awk_script2.txt" *.cva > $file_lista
        }
}cd ..

cd $StartingFolder

#### end of the script



4 commenti:

  1. Hi there, where do you get the awk_script.txt and awk_script_deviceID_softpaq.txt files? Also what is in the emtpy_repository.json file? It a completely blank txt/json file?

    & $StartingFolder"\gawk.exe" -f $StartingFolder\awk_script_deviceID_softpaq.txt *.cva > all_Devices_softpaq.txt
    & $StartingFolder"\gawk.exe" -f $StartingFolder\awk_script.txt *.cva > list_all_softpaq.txt

    RispondiElimina
    Risposte
    1. Hello
      I'm sorry to answer you so late.
      I updated the script and now I sue HP CMSL 1.4.3.
      if you are still interested write another comment, either in Englis or Italian, I'll check if I receive it , I'll be happy to share my experience.

      Elimina
  2. Hi,

    can I check with you whether this script is updated? As I faced some issues with missing awk_script_deviceID_softpaq.txt *.cva

    RispondiElimina
  3. Hello Steven, please send me an email to esalvotti@gmail.com, so I can share with you what I done.

    bye

    RispondiElimina