Automating Maintenance of HP Image Assistant Repositories (Upd 10/20/2020)

HP Image Assistant can install/update drivers and other components from an offline repository that has been populated with Softpaqs for HP supported business systems. A Repository folder, if to be used by HPIA, requires to be configured correctly. Configuring can be done with HP's Client Management Software Library. This blog highlights a Powershell script that helps automate the creation and maintenance of such repositories

In previous blogs, we reviewed methods to inject drivers with HP Image Assistant into Microsoft Endpoint Configuration manager. The methods described in the blog used file repositories managed by the HP’s Client Management Script Library. HP Image Assistant (HPIA), while running on a client PC during imaging steps can draw the latest drivers from the managed repository and inject them facilitating the process of imaging new PCs. On a different blog, we discussed how to update drivers with HPIA to help enterprises keep deployed systems up to date. Here we packaged HPIA as an application that with a runstring option connected to a server-hosted file repository, where it pulled newer Softpaqs for the client it is running on.

The script described here, and hosted on Github, is designed to create file repositories as required from each model selected in the GUI, configure them for HPIA and when clicking on Sync, download all available Softpaqs (latest only) for the selected categories.

As with previous blogs, the script requires that the HP CMSL module be loaded on the system (PC or server) it runs on. Otherwise, PowerShell will complain on the use of repository cmdlets within the script. The module can be loaded from the PS Gallery - as Administrator: 

Import-Module -name 'HPCMSL' -SkipPublisherCheck -AcceptLicense -Force

Note that for some systems, the PowerShellProvider NuGet and module PowerShellGet may need to be updated to add the HPCMSL module from the Gallery.

Install-PackageProvider -name NuGet -Force
Install-Module PowerShellGet -SkipPublisherCheck -Force
Update-Module -Name PowerShellGet

 

Also, note that PoweShell scripts have to be allowed to execute. If needed, scripts can be enabled with a command such as

Set-executionpolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine

The script interface will keep track of what is selected, and repopulate the settings on restart.

The script will

  • Check for the presence of the HP CMSL module - TBD with feature update
  • Will read the contents of the INI file to retrieve local, specific, information, including
    • OS Version selected
    • Categories of Softpaqs to be used as filters (each in its own column)
    • Models list
    • Path to host repositories, with each model having its own folder repository
    • Path to log file
    • Setting to enable access to the local MECM environment to create/update repository packages. If disabled, the script will ONLY populate repositories. The setting is shown on the user interface, where it can also be modified
  • Will check for the main repository folder, and create it if not already created
  • If any models are already selected (from a previous run), it will check for repository filters and populate the GUI accordingly.
  • For each model selected. The appropriate path is shown in the last column
  • Provides a Sync button to sync and clean up each repository the user selects for update

NOTE: selecting a different OS Version in the GUI will make that version default to all systems. Pressing Sync will then have the HP CMSL repository commands search for Softpaqs matching each category and OS version to update the model’s repository.

The first column of checkmarks indicate if ANY model has some selected categories to sync. Putting a checkmark on this column will also select the ‘Driver’ category. The reason is simply that in most cases, HPIA is used to update hardware-enabling drivers so we chose to set it automatically. On the same row, selecting from the ‘All’ column will select/enable all categories for that model.

The local configration options are kept in an ini file, HPIARepo_ini.ps1

<#
    File: HPIARepo_ini.ps1
    Dan Felman/HP Inc
    7/23/2020
    modify variables as need for use by the Downloader script
#>
$OS = "Win10"
$OSVER = "1909"                                # entry can be midified in the GUI
$OSVALID = @("1809", "1903", "1909", "2004")   # add/remove as needed
$FilterCategories = @('Driver','BIOS', 'Firmware', 'Software')
#-------------------------------------------------------------------
# Example systems to manage
#
$HPModelsTable = @(
    @{ ProdCode = '8438'; Model = "HP EliteBook x360 1030 G3" }
    @{ ProdCode = '83B3'; Model = "HP ELITEBOOK 830 G5" }
    @{ ProdCode = '83B2'; Model = "HP ELITEBOOK 840 G5" }
    @{ ProdCode = '8549'; Model = "HP ELITEBOOK 840 G6" }@{ ProdCode = '8470'; Model = "HP ELITEBOOK X360 1040 G5" }
    @{ ProdCode = '844F'; Model = "HP ZBook Studio x360 G5" }
    @{ ProdCode = '8593'; Model = "HP EliteDesk 800 G5 Desktop Mini PC" }
    @{ ProdCode = '8549'; Model = "HP EliteBook 840 G6 Healthcare Edition" }
    @{ ProdCode = '859F'; Model = "HP EliteOne 800 G5 All-in-One" }
    )
$FileServerName = $Env:COMPUTERNAME 

# choose/edit a path from next 2 lines for the location of the main repository folder
# next for use in multiple repositories/one per model
$RepoShareMain = "\\$($FileServerName)\share\softpaqs\HPIARepo"
#$RepoShareMain = "C:\share\softpaqs\HPIARepo"

# 7/23 NEW: and this for use when selecting a single repository (use with Script version >= 1.15
$RepoShareSingle = "\\$($FileServerName)\share\softpaqs\HPIACommonRepository"
#$RepoShareSingle = "C:\share\softpaqs\HPIACommonRepository"

$LogFile = "$PSScriptRoot\HPDriverPackDownload.log"               # Default to location where script runs from

# next setting makes the script work with Microsoft SCCM/MECM, if set to $true
# it can be modified in the main script, as needed
$UpdateCMPackages = $False

# 7/21 NEW: manage single repository folder, instead of individual per model
$SingleRepo = $False

# if there are errors during startup, set this to $true, for additional startup info
$DebugMode = $false

Selecting 'Debug Mode' allows the script to output additional steps it is doing

If a row/Model is deselected, the script will NOT attempt to remove the contents of the repository if one existed. It will remain in place. The contents of the repository can be cleaned up by removing the folder, that includes all softpaqs, the .Reporitory folder, etc.

Update 1.10

This update of the Repository downloader script adds the ability to select a single repository for all models. The checkmark, when selected, will be maintained in the INI file

Version 1.15

This version adds a separate variable for a common/master repository instead of using the main repo used as the head of individual repositories. To set it up, modify the Main share variable (as either a \\ share, or a driver letter C:\... pick one line in the INI file to suite your environment - change as appropriate

$RepoShareMain = "\\$($FileServerName)\share\softpaqs\HPIARepo"
#$RepoShareMain = "C:\share\softpaqs\HPIARepo"

and do the same for using a common/single master repository for all systems

$RepoShareSingle = "\\$($FileServerName)\share\softpaqs\HPIACommonRepository"
#$RepoShareSingle = "C:\share\softpaqs\HPIACommonRepository"

To clean up repositories:

If single repository, all filters are removed during a Sync and the following cleanup will remove any softpaqs not part of the selected models and categories in the GUI.

For individual repositories, there is a general clean up any time a category changes. To remove a model, just delete the repository folder.

Update 1.30

In order to provide the ability to select specific Softpaqs to download and maintain for HPIA's use, the script was modified to allow a select 'named' set of softpaqs be downloaded on a per model basis. The updated INI file extends the $HPModelsTable to include a list of Softpaqs to keep track of. The Main script then downloads each in its own repository subfolder (so that CMSL's Invoke-RepositorySync/Cleanup will not delete them) and copies those files to the repository as appropriate.

The INI file is then modified, for example...

<#
    File: HPIARepo_ini.ps1

    Dan Felman/HP Inc
    7/27/2020

    modify variables as need for use by the Downloader script
#>
$OS = "Win10"
$OSVER = "2004"
$OSVALID = @("1809", "1903", "1909", "2004")

$FilterCategories = @('Driver','BIOS', 'Firmware', 'Software')

#-------------------------------------------------------------------
# Example systems to manage
#
# NEW 1.30 - added list of individual softpaq names to host in repository
$NBSet1 = 'HP Collaboration Keyboard Software' , 'HP Hotkey Support' , 'System Default Settings for Windows 10' , 'HP Notifications'
$NBSet2 = 'HP Hotkey Support' , 'System Default Settings for Windows 10' , 'HP Notifications'
$DTSet1 = 'HP Notifications'

$HPModelsTable = @(
	@{ ProdCode = '8598'; Model = "HP ProDesk 600 G5 DM";                   SqName = $DTSet1  }
	@{ ProdCode = '8438'; Model = "HP EliteBook x360 1030 G3";              SqName = $NBSet1  }
	@{ ProdCode = '83B3'; Model = "HP ELITEBOOK 830 G5";                    SqName = $NBSet1  }
	@{ ProdCode = '83B2'; Model = "HP ELITEBOOK 840 G5";                    SqName = $NBSet1  }
	@{ ProdCode = '8549'; Model = "HP ELITEBOOK 840 G6";                    SqName = $NBSet2  }
	@{ ProdCode = '8470'; Model = "HP ELITEBOOK X360 1040 G5";              SqName = $NBSet1  }
	@{ ProdCode = '844F'; Model = "HP ZBook Studio x360 G5";                SqName = $NBSet1  }
	@{ ProdCode = '8593'; Model = "HP EliteDesk 800 G5 Desktop Mini PC";    SqName = $DTSet1  }
        @{ ProdCode = '8549'; Model = "HP EliteBook 840 G6 Healthcare Edition"; SqName = $DTSet1  }
        @{ ProdCode = '859F'; Model = "HP EliteOne 800 G5 All-in-One";          SqName = $DTSet1  }
    )

$FileServerName = $Env:COMPUTERNAME 

#-------------------------------------------------------------------
# choose/edit a path from next 2 lines for the location of the main repository folder

# next for use in multiple repositories/one per model
$RepoShareMain = "\\$($FileServerName)\share\softpaqs\HPIARepo"
#$RepoShareMain = "C:\share\softpaqs\HPIARepo"

# 7/23 NEW: and this for use when selecting a single repository (use with Script version >= 1.15
$RepoShareCommon = "\\$($FileServerName)\share\softpaqs\HPIACommonRepository"
#$RepoShareCommon = "C:\share\softpaqs\HPIACommonRepository"

#-------------------------------------------------------------------
$LogFile = "$PSScriptRoot\HPDriverPackDownload.log"               # Default to location where script runs from

#-------------------------------------------------------------------
# next setting makes the script work with Microsoft SCCM/MECM, if set to $true
# it can be modified in the main script, as needed
$UpdateCMPackages = $False
$DistributeCMPackages = $False

#-------------------------------------------------------------------
# 7/21 NEW: manage single repository folder, instead of individual per model
$CommonRepo = $False

# if there errors during startup, set this to $true, for additional info
$DebugMode = $false

There is also a general cleanup of the messages displayed with more of them only available when either the '[ ] Debug mode' checkbox is set or the variable in the INI file is set to $True (for additional startup debug messages that would not be seen if problems arise before the UI is created)

Version 1.25 and newer also include a new' [ ] Distribute Packages' checkmark to allow the creation/update of SCCM packages to not automatically update distribution points, unless desires

The 'Clear TexBox' button clears out the message box, and the new 'Refresh Grid Filters' button will refresh the list from information on the File Repositories.

NOTE: named Softpaqs are downloaded to a .ADDSOFTWARE subfolder. If this folder is removed, it will be recreated on next Sync. Also, there is no Softpaq maintenance done, so if a newer version for a particular Softpaq is downloaded, the previous version is not deleted, but it can be removed manually if the space is needed.

Version 1.32

This version adds the ability to create an HPIA package in SCCM, and update it should the program upgrade to a new version. Pressing on [Update HPIA] button checks to make sure SCCM is available on the system the script runs and then either creates a package pointing the source to the HPIA folder, or updates the package with the folder listed in the INI (and shown in the UI).

The message textbox will also show sync information from the last invoke-reporitorysync command, which is also posted to the script's log file.

version 1.40

This version adds several enhancements. First, the size of the dialog has increased to allow for better use of display. A new checkbox allows the user to maintain existing filters (say, for an older OS version while adding filters for a new OS). The checkbox is just below the Sync button. Then, there is the ability to list all existing filters for each system. Finally, we added buttons to increase (and decrease) the text box up to 4 sizes for better legibility

version 1.45

In order to help diagnose HP Script Library sync issues, code was added to attempt to obtain the remote connection's IP address. If obtained, the remote and local (public) IP addresses are displayed in the UI as well as logged in the script's log file. The connection information is tied to the function and CMSL cmdlet for help in troubleshooting steps

In addition, the log file name is now also shown in the UI (retrieved from the INI.ps1 file

version 1.50

        Added protection against Platform/OS Version not supported
        Added ability to start a New log file w/checkmark in IU - log saved to log.bak0,log.bak1, etc.

version 1.51

Removed All column (was selecting all categories with single click
Added 'INI S/W' column to allow/disallow download of software listed in INI.ps1 file
Fixed UI issues when clicking/selecting or deselecting categories and Model row checkboxes

version 1.62 (9/16/2020)

Versions newer then 1.60 add runtime options. The script will now be able to be scripted and executed as a Windows scheduled job

When running the script with runtime options, it assumes repositories have been created and available. If the -Products runtime option is added, only the list of product IDs will be sync'd and nothing else will be touched. If -Products is not added, then the list of systems will be obtained from the INI.ps1 file, again it will assume that the script was run in UI mode first and repositores for those systems are alreay created  with the appropriate filters

Option -help will show options and terminate

Option -Sync will execute the script with or without additional options

The following options are available:

-help|-h
-inifile <path to ini.ps1 file>                   # Defaults to ".\HPIARepo_ini.ps1"... can also be 1st arg in command line
-RepoStyle <Individual | Common>      # Defaults to setting in ".\HPIARepo_ini.ps1"
-Products @()                                       # List of Produc ID's... default is to use existing repositories
-ListFilters                                             # Switch: to show what filters exist in each reporitory
-noIniSw                                                # Switch: to disable use of alternate named Softpaqs by name in INI file
-showActivityLog                                   # Switch: enable output of additional activity from HPIA log file
-new Log                                               # Switch: back up existing log file and start new script log
-Sync                                                    # Switch: command to sync and maintain repositories
 

A sample job scheduling script is available on Github, and shown next

<#
    reposcriptTest.ps1

    Developed by:
        Dan Felman
        HP Inc Technical Consultant
        9/15/2020

    This is a sample script to show how to schedule the HPIARepo_Downloader script v1.62 and later with runtime options

    'HPIARepo_Downloader' runtime options:

    -IniFile <filepath.ini> -ListFilters -RepoStyle <common|individual> -Sync -NoIniSw -ShowActivityLog -Products <>80D4,8549,8470> -newLog 

        -IniFile   defaults to '.\HPIARepo_ini.ps1'
        -RepoStyle defaults from $CommonRepo variable in IniFile
        -Products  defaults to $HPModels list in IniFile. 
            In either case, corresponding repositories must exist, or product is bypassed

    NOTE: modify location for local environment
          modify options as needed
#>

# this is the PS script block that gets scheduled... modify as needed

$HPIABlock = { 
    & Set-Location 'C:\Users\Administrator.VIAMONSTRA\Documents\Manageability_demo_files\Scripts\WiP'
    & .\HPIARepo_Downloader_1.62.ps1 -ListFilters -RepoStyle individual -ShowActivityLog -Sync -NoIniSw -Products 80D4,8549,8470 -newLog 
}

# let's schedule the Downloader as a Windows Task job
# if job (by name) already exists, just report it, otherwise, schedule it

#--------------------------------------------------------------------------------------

$scheduleTime = '16:56'                           # NOTE: Modify when to schedule job                      

$doJob = $true                                    # default is to schedule the job
$ScheduledJobs = Get-ScheduledJob                 # obtain existing scheduled jobs
$TriggerName = 'HPIATrigger'                      # name of the job... Modify if needed

# find out if the Trigger is already in use

if ( $ScheduledJobs -ne $null ) {
    foreach ( $currJob in $ScheduledJobs ) {
        if ( $currJob.Name -match $TriggerName ) {
            $doJob = $false
            write-host "Trigger found (shown next). Can't schedule another Job with same Trigger name. To remove type: 'Unregister-ScheduledJob -id $($currJob.id)'"
            Get-ScheduledJob -Name $TriggerName
        } # if ( $currJob.Name -match 'HPIATrigger' )
    } # foreach ( $currJob in $jobs ) 
}

# If Trigger not yet scheduled, let's do it now
# but make sure we have admin rights first

if ( $doJob ) {
    $adminRights = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
    If( $adminRights ) {
        'Scheduling job. User is a member of local administrators'
        ## NOTE some Options: 
        ##    -Once <-At "1/20/2012 3:00 AM">
        ##    -Weekly -DaysOfWeek <DayOfWeeklist[]> <-At "3:00 AM">
        ##    -Daily <-At "1/20/2012 3:00 AM">
        ##    -AtLogon
        ##    -AtStartup
        ## ( https://docs.microsoft.com/en-us/powershell/module/psscheduledjob/new-jobtrigger?view=powershell-5.1 )
        $trigger = New-JobTrigger -Once -At $scheduleTime          
        Register-ScheduledJob -Name $TriggerName -Trigger $trigger -ScriptBlock $HPIABlock
    } Else {
        'Can not schedule job. User is not a member of local administrators'
    } # else If( $adminRights )
}

#--------------------------------------------------------------------------------------
# Powershell scheduling job commands
#--------------------------------------------------------------------------------------

# Get-ScheduledJob
# Get-ScheduledJob -Name HPIATrigger
# Unregister-ScheduledJob -Name HPIATrigger

# Remove-JobTrigger -Name HPIATrigger

version 1.65

Adds Browse button for sourcing updated HP Image Assistant folder... requires finding HPImageAssistant.exe

Adds support for managing Softpaqs by SP name in INI file

version 1.66

Adds dialog during Sync to remove (or not) not selected filters and softpaqs from repository that were selected previously --- this is a way to remove Softpaqs from models no longer needed

version 1.70

Adds a checkbox in the GUI to enable the CMSL Sync command to continue should it encounter a File NOT Found error (404). The default is set to True in HPIARepo_ini.ps1

Author : dan.felman

HPIA downloader PS script

The top part to add the module is not correct this worked for me . Install-Module -Name HPCMSL -SkipPublisherCheck -AcceptLicense -Force

it has been kind of hard to figure out the proper requirements for having all things needed to support importing the CMSL module... 1) after updating powershellget module, the program and PS need to exit and restart (i am adding this to code as we speak)... 2) try removing the -AcceptLicense option from the runstring

You should not normally need the -SkipPublisherCheck. However I believe the signing certificate CN has changed between 1.4 and 1.5, which will cause a warning, since PS will see a different certificate for 1.5.

How do I handle this: PS C:\WINDOWS\system32> Get-HPDeviceDetails -platform '8079' SystemID Name DriverPackSupport -------- ---- ----------------- 8079 HP EliteBook 840 G3 Notebook PC True 8079 HP EliteBook 848 G3 Notebook PC True 8079 HP EliteBook 850 G3 Notebook PC True 8079 HP ZBook 15u G3 Mobile Workstation True They are the same product code but different names. We have the top three in this list. Do I put in 3 entries or just 1?

very good question. because the repositories, when using individual folders are based on system names, you would have to include each model in the list. However, an option could be that you use a single model, say the HP EliteBook 840 G3 and then point your HPIA run to that repository for each model - and remember that since the CMSL repository commands sync the repository for the product code (in this case 8079), it would support all 3 versions of the G3 laptops. This would prevent triplicating the repositories, one per model on the other hand, if you setup a shared/common repository for all models, then you can have all models listed in the HPModels list and once the filters are applied in the UI, the Sync and Cleanup commands would make sure no duplicate Softpaqs are maintained. BTW, i have developed a new version (to post soon) that includes runtime options, which would allow the Downloader script to be scheduled to run on a regular basis. Hopefully, it will be useful to some users