HP Download BIOS and Update CM Packages

Just did this with Dell, now it’s HP’s turn, wrote a script that checks our HP BIOS packages in CM, then compares to what HP has available and updates accordingly.

If you haven’t noticed… I’m in the middle of automating updating our CM Packages …

I’m not going to go into much detail, look at the Dell versions for more info
Post HERE: https://garytown.com/dell-bios-download-and-update-cm-package

 

You’ll need to update several variables in the script, like FileServer, Package IDs, etc.  Please read through the script before running.
Table of models that I’m currently downloading BIOS for, you’ll need to update for your environment. (You’ll need the HP Product Code, that’s what the HP Tools use).
Sorry, notes in the script are a bit lacking.

image

image

Email Report:
image

image

Requires HP Script Library: https://developers.hp.com/hp-client-management/doc/client-management-script-library

My Post on Scripted Install: https://garytown.com/download-install-the-latest-hp-script-library-via-powershell

Script:

<#  Creator @gwblok - GARYTOWN.COM
    Used to download BIOS Updates from HP
    This Script was created to build a BIOS Update Package. 
    Future Scripts based on this will be one that gets the Model / Product info from the machine it's running on and pull down the correct BIOS and run the Updater

    REQUIREMENTS:  HP Client Management Script Library
    Download / Installer: https://ftp.hp.com/pub/caps-softpaq/cmit/hp-cmsl.html  
    Docs: https://developers.hp.com/hp-client-management/doc/client-management-script-library-0
    This Script was created using version 1.2.1
#>
[CmdletBinding()]
    Param (
		    [Parameter(Mandatory=$true,Position=1,HelpMessage="Application")]
            [ValidateNotNullOrEmpty()]
            [ValidateSet("Report", "Download", "DownloadOnly", "UpdateCMPackageOnly")]
		    $RunMethod = "Report"
 	    )


#Settings for Google - Rest of Info @ Bottom
$SMTPServer = "smtp.gmail.com"
$SMTPPort = "587"
$Username = "youremail@gmail.com"
$Password = "yourpassword"

#Script Vars
$EmailArray = @()
$scriptName = $MyInvocation.MyCommand.Name
$FileServerName = "SRC"
$OS = "Win10"
$Category = "bios"
$LogFile = "$PSScriptRoot\HPBIOSDownload.log"
$DownloadDir = "C:\HPContent\Downloads"
$ExtractedDir = "C:\HPContent\Packages\HP"
$SiteCode = "PS2"

#Reset Vars
$BIOS = ""
$Model = ""



 

#region: CMTraceLog Function formats logging in CMTrace style
        function CMTraceLog {
         [CmdletBinding()]
    Param (
		    [Parameter(Mandatory=$false)]
		    $Message,
 
		    [Parameter(Mandatory=$false)]
		    $ErrorMessage,
 
		    [Parameter(Mandatory=$false)]
		    $Component = "HP BIOS Downloader",
 
		    [Parameter(Mandatory=$false)]
		    [int]$Type,
		
		    [Parameter(Mandatory=$true)]
		    $LogFile
	    )
    <#
    Type: 1 = Normal, 2 = Warning (yellow), 3 = Error (red)
    #>
	    $Time = Get-Date -Format "HH:mm:ss.ffffff"
	    $Date = Get-Date -Format "MM-dd-yyyy"
 
	    if ($ErrorMessage -ne $null) {$Type = 3}
	    if ($Component -eq $null) {$Component = " "}
	    if ($Type -eq $null) {$Type = 1}
 
	    $LogMessage = "<![LOG[$Message $ErrorMessage" + "]LOG]!><time=`"$Time`" date=`"$Date`" component=`"$Component`" context=`"`" type=`"$Type`" thread=`"`" file=`"`">"
	    $LogMessage | Out-File -Append -Encoding UTF8 -FilePath $LogFile
    }

function Get-FolderSize {
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
$Path,
[ValidateSet("KB","MB","GB")]
$Units = "MB"
)
  if ( (Test-Path $Path) -and (Get-Item $Path).PSIsContainer ) {
    $Measure = Get-ChildItem $Path -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum
    $Sum = $Measure.Sum / "1$Units"
    [PSCustomObject]@{
      "Path" = $Path
      "Size($Units)" = $Sum
    }
  }
}



if ((Test-NetConnection proxy-garytown.com -Port 8080).PingSucceeded -eq $True)
    {
    $UseProxy = $true
    CMTraceLog -Message "Found Proxy Server, using for Downloads" -Type 1 -LogFile $LogFile
    Write-Output "Found Proxy Server, using for Downloads"
    $ProxyServer = "http://proxy-garytown.com:8080"
    $BitsProxyList = @("192.168.1.176:8080, 168.33.22.169:8080, 111.222.214.218.21:8080")
    }
Else 
    {
    CMTraceLog -Message "No Proxy Server Found, continuing without" -Type 1 -LogFile $LogFile
    Write-Output "No Proxy Server Found, continuing without"
    }

    
        $HPModelsTable= @(
        @{ ProdCode = '80FC'; Model = "Elite x2 1012 G1"; PackageID = "PS200088"}
        @{ ProdCode = '82CA'; Model = "Elite x2 1012 G2"; PackageID = "PS200089" }
        @{ ProdCode = '80FB'; Model = "EliteBook 1030 G1"; PackageID = "PS20008A" }
        @{ ProdCode = '80FA'; Model = "EliteBook 1040 G3"; PackageID = "PS20008B"  }
        @{ ProdCode = '225A'; Model = "EliteBook 820 G2"; PackageID = "PS20008C"  }
        @{ ProdCode = '807C'; Model = "EliteBook 820 G3"; PackageID = "PS20008D"  }
        @{ ProdCode = '2216'; Model = "EliteBook 840 G2"; PackageID = "PS20008E"  }
        @{ ProdCode = '8079'; Model = "EliteBook 840 G3"; PackageID = "PS20008F"  }
        @{ ProdCode = '827D'; Model = "EliteBook x360 1030 G2"; PackageID = "PS200090"}
        @{ ProdCode = '83D2'; Model = "ProBook 640 G4"; PackageID = "PS200091" }
        @{ ProdCode = '8062'; Model = "ProDesk 400 G3"; PackageID = "PS200092" }
        @{ ProdCode = '82A2'; Model = "ProDesk 400 G4"; PackageID = "PS200093"  }
        @{ ProdCode = '83F2'; Model = "ProDesk 400 G5"; PackageID = "PS200094"  }
        @{ ProdCode = '21D0'; Model = "ProDesk 600 G1"; PackageID = "PS200095"  }
        @{ ProdCode = '8053'; Model = "ProDesk 600 G2"; PackageID = "PS200096"  }
        @{ ProdCode = '829E'; Model = "ProDesk 600 G3"; PackageID = "PS200097"  }
        @{ ProdCode = '83EF'; Model = "ProDesk 600 G4"; PackageID = "PS200098"  }
        )


CMTraceLog -Message "Starting Script: $scriptName" -Type 1 -LogFile $LogFile
Write-Output "Starting Script: $scriptName"

Try {Test-Connection -ComputerName "$FileServerName" -Quiet 
    $DownloadBIOSRootArchive = "\\$($FileServerName)\src$\osd\Firmware\HPArchive"
    $DownloadBIOSRootPackage = "\\$($FileServerName)\src$\osd\Firmware\HP"
    $DownloadToServer = $true
    Write-Output "Connected to Server $FileServerName"
    $EmailArray += "<font color=Black>Script was run in Mode: $($RunMethod)</font><br>"
    $EmailArray += "<font color=Black>Connecting to File Share Server: $($FileServerName)</font><br>"
    if  (Test-Path 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin'){Import-Module 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1'}
    }
Catch 
    {
    Write-Output "Not Connected to File Server, Exiting"
    $DownloadToServer = $false
    }


foreach ($HPModel in $HPModelsTable)
    {
    Write-Output "Checking Product Code $($HPModel.ProdCode) for BIOS Updates"
    #$BIOS = Get-SoftpaqList -platform $Model.ProdCode -os $OS -category $Category
    $BIOS = Get-HPBiosUpdates -platform $HPModel.ProdCode -latest
    $DownloadBIOSRootArchiveFullPath = "$($DownloadBIOSRootArchive)\$($HPModel.Model)\$($BIOS.ver)"
    $DownloadBIOSRootPackageFullPath = "$($DownloadBIOSRootPackage)\$($HPModel.Model)\Pilot"   
   #Get Current Driver CMPackage Version from CM
    if ($DownloadToServer -eq $true)
        {
        Set-Location -Path "$($SiteCode):"
        $PackageInfo = Get-CMPackage -Id $HPModel.PackageID -Fast
        $PackageInfoVersion = $PackageInfo.Version
        Set-Location -Path "C:"
        }
    Else
        {
        $PackageInfoVersion = $null
        }
    if ($PackageInfoVersion -eq $Bios.ver)
        {Write-Output "$($HPModel.Model) already current with version $($PackageInfoVersion)"
        CMTraceLog -Message "CM Package $($PackageInfo.Name) already Current: $PackageInfoVersion HP: $($Bios.Ver)" -Type 1 -LogFile $LogFile
        $EmailArray += "<font color=Green>CM Package <b>$($PackageInfo.Name)</b> Already Current</font><br>"
        $EmailArray += "<font color=Green>&emsp;CM Package Version Currently: $PackageInfoVersion. Dell Online Version: $($Bios.Ver)</font><br>"
        $AlreadyCurrent = $true
        }
    else
        {Write-Output "$($HPModel.Model) package is version $($PackageInfoVersion), new version available $($BIOS.ver)"
        if (-not(Test-Path $DownloadBIOSRootArchiveFullPath)) {new-Item -Path $DownloadBIOSRootArchiveFullPath -ItemType Directory -Force }
        $SaveAs = "$($DownloadBIOSRootArchiveFullPath)\$($Bios.Bin)"
        Get-HPBiosUpdates -platform $HPmodel.ProdCode -download -saveAs $SaveAs -overwrite
        if (Test-Path $DownloadBIOSRootPackageFullPath) {Remove-Item -Path $DownloadBIOSRootPackageFullPath -Recurse -Force }
        New-Item $DownloadBIOSRootPackageFullPath -ItemType Directory -Force
        Copy-Item $SaveAs -Destination $DownloadBIOSRootPackageFullPath -Force
        $AlreadyCurrent = $false
        }
    
    if (($RunMethod -eq "Download" -and $AlreadyCurrent -ne $true) -or $RunMethod -eq "UpdateCMPackageOnly")
        {
        write-output "Updating Package Info in ConfigMgr $($PackageInfo.Name) ID: $($HPModel.PackageID)"
        Import-Module 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1'
        Set-Location -Path "$($SiteCode):"         
        Set-CMPackage -Id $HPModel.PackageID -path "$($DownloadBIOSRootPackageFullPath)"
        Set-CMPackage -Id $HPModel.PackageID -Version "$($BIOS.Ver)"
        #Set-CMPackage -Id $HPModel.PackageID -DriverPkgVersion $Target.dellVersion
        #Set-CMPackage -Id $HPModel.PackageID -DriverModel $HPModel.Model
        #Set-CMPackage -Id $HPModel.PackageID -DriverManufacturer "Dell"
        Set-CMPackage -Id $HPModel.PackageID -Description "Version $($Bios.ver) Released $($Bios.Date).  Archive Folder = $($DownloadBIOSRootArchiveFullPath)"
        #Set-CMPackage -Id $HPModel.PackageID -Language $TargetKBID
        Set-CMPackage -ID $HPModel.PackageID -Manufacturer "HP"
        $PackageInfo = Get-CMPackage -Id $HPModel.PackageID -Fast
        $EmailArray += "<font color=#8B0000>Updated Package $($PackageInfo.Name), ID $($HPModel.PackageID) Information: </font><br>"
        $EmailArray += "<font color=#8B0000>&emsp;Version set from $($PackageInfoVersion) to: $($Bios.ver) </font><br>"
        #$EmailArray += "<font color=#8B0000>&emsp;Language set to: $TargetKBID</font><br>"
        $EmailArray += "<font color=#8B0000>&emsp;Desciption set to: Version $($Bios.ver) Released $($Bios.Date).  Archive Folder = $($DownloadBIOSRootArchiveFullPath) </font><br>"
        Update-CMDistributionPoint -PackageId $HPModel.PackageID
        Set-Location -Path "C:"
        CMTraceLog -Message "Updated Package $($PackageInfo.Name), ID $($HPModel.PackageID) to $($PackageInfoVersion) which was released $($TargetDate)"  -Type 1 -LogFile $LogFile
        }
}  

#Settings for Email
#Customize this Part for your Subject & Body.  Keep it short if you plan to use SMS texts.
$to = "youremail@gmail.com"
$subject = "HP BIOS Updates"
$body = "$EmailArray" 
$message = New-Object System.Net.Mail.MailMessage
$message.subject = $subject
$message.body = $body
$message.IsBodyHTML = $true
$message.to.add($to)
$message.from = $username
        
$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
$smtp.EnableSSL = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$smtp.send($message)
write-host "Mail Sent"


CMTraceLog -Message "Finished Script: $scriptName" -Type 1 -LogFile $LogFile
Write-Output "Finished Script: $scriptName"

 

 

Posted on GARYTOWN.COM

5 thoughts on “HP Download BIOS and Update CM Packages”

  1. Can you tell me how to find the model/product ID info for my specific models? I ran the ps command to get the ProdID but the UpdateRepos script errors out saying it cannot find a data file.

    Reply
    • Hi Gary,

      Thanks for your post, do you think I can use your script for HP Prodesk 600 G3 ( it’s in your script) do I still need the product code? Also can remove the other models because we have just one?
      Thanks again

      Reply
      • Yes, you can use it for just one model, clear out the ones you don’t want.
        Yes, you should have the Product Code included for all HP Devices.

        Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.