.SYNOPSIS
Updates BIOS version on a HP hardware
.DESCRIPTION
Updates BIOS version on several HP EliteBook und EliteDesk models. Die HP Tools and the new BIOS files (.bin or .cab)
should be in the same folder with the script. The new BIOS versions can be downloaded from the link below.
The script is not supported under any standard support program or service.
The script is provided AS IS without warranty of any kind.
.PARAMETERS
There is no parameters
.EXAMPLE
Update-BIOS.ps1
.NOTES
Script name: Update-BIOS.ps1
Author: Dejan Milic
Contact: @DMI99
DateCreated: 2018-05-05
Disclaimer:
The sample script is not supported under any standard support program or service. The sample script is provided
AS IS without warranty of any kind.
.LINK
https://support.hp.com/us-en/drivers
#>
#==============================================
# Declare Variables
#==============================================
[String]$LogFile = "$env:WinDir\CCM\Logs\app\" + $($((Split-Path $MyInvocation.MyCommand.Definition -leaf)).replace("ps1","log"))
#==============================================
# Declare Functions
#==============================================
Function Write-ToLog([string]$message, [string]$file) {
<#
.SYNOPSIS
Writing log to the logfile
.DESCRIPTION
Function to write logging to a logfile.
#>
If(-not($file)){$file=$LogFile}
$Date = $(get-date -uformat %Y-%m-%d-%H.%M.%S)
$message = "$Date `t$message"
Write-Verbose $message
Write-Host $message
#Write Log to log file Without ASCII not able to read with tracer.
Out-File $file -encoding ASCII -input $message -append
}
function Check-OnAC() {
<#
.SYNOPSIS
Checking if notebook is on AC
.DESCRIPTION
Function to check if notebook is connected to AC.
If connected to AC or if computer is not a notebook
the function returns $true otherwise returns $false
#>
Write-ToLog "Check if computer on AC"
$onAC = $True
#Check if computer is a notebook
Write-ToLog "Check if computer is a notebook"
if ((Get-WMIObject -Class Win32_ComputerSystem).PCSystemType -eq 2)
{
Write-ToLog "The computer is a notebook."
# Check if the notebook is not running on battery power
if (!((Get-WMIObject -Class BatteryStatus -Namespace root\wmi).PowerOnline))
{
$onAC = $False
Write-ToLog "The computer is NOT connected to AC."
} else {
Write-ToLog "The computer is connected to AC."
}
}
return $onAC
}
#==============================================
# Main Script
#==============================================
# Check if %WinDir%\ccm\logs\app folder exists
if(-not(Test-Path -Path "$env:WinDir\CCM\Logs\app"))
{
New-Item -Path "$env:WinDir\CCM\Logs" -Name "app" -Type Directory
Write-ToLog "$env:WinDir\CCM\Logs\app folder has been created"
}
Write-ToLog "####### Script has been started ######"
Write-ToLog "Check if computer connected to AC"
$UpdateBIOS = Check-OnAC
#Update BIOS
if ($UpdateBIOS)
{
Write-ToLog "Updating BIOS"
# Suspend Bitlocker -> Separate Step in TS - removed
$BLStatus = (Get-WmiObject -Namespace root\cimv2\Security\MicrosoftVolumeEncryption -Class Win32_EncryptableVolume -Filter "DriveLetter = 'C:'").ProtectionStatus
if($BLStatus -eq 1)
{
Write-ToLog "Disable BitLocker"
manage-bde.exe -protectors -disable c:
}
Write-ToLog "Check model"
# Get computer modell
$CSWMI = (Get-WmiObject -class Win32_Computersystem).Model
Write-ToLog "Computer model detected: $CSWMI"
# Select requiered BIOS file
Write-ToLog "Select .bin BIOS file"
switch -Wildcard ($CSWMI)
{
"HP EliteBook 820 G1*"
{
$BiosFile = "L71_0143.bin"
continue
}
"HP EliteBook 840 G1*"
{
$BiosFile = "L71_0143.bin"
continue
}
"HP EliteBook 820 G2*"
{
$BiosFile = "M71_0124.bin"
continue
}
"HP EliteBook 840 G2*"
{
$BiosFile = "M71_0124.bin"
continue
}
"HP EliteBook 820 G3*"
{
$BiosFile = "N75_0124.bin"
continue
}
"HP EliteBook 840 G3*"
{
$BiosFile = "N75_0124.bin"
continue
}
"HP EliteBook 850 G3*"
{
$BiosFile = "N75_0124.bin"
continue
}
"HP EliteDesk 800 G1*"
{
$BiosFile = "rom.cab"
continue
}
"HP EliteDesk 800 G2 DM*"
{
$BiosFile = "N21_0232.bin"
continue
}
"HP EliteDesk 800 G2 TWR*"
{
$BiosFile = "N01_0228.bin"
continue
}
"HP EliteBook 820 G4*"
{
$BiosFile = "P78_0115.bin"
continue
}
"HP EliteBook 840 G4*"
{
$BiosFile = "P78_0115.bin"
continue
}
} # End switch
Write-ToLog "BIOS File selected: $BiosFile"
# Get PSW bin files
Write-ToLog "Get PSW bin files"
$Bins = Get-ChildItem -Filter BIOSPW*.bin
$Target = $Bins.Length
Write-ToLog "$Target BISOPW.bin files found"
for ($i=$Target; $i -gt 0; $i--) {
Write-ToLog "Try BIOS update with BIOSPW$i.bin file"
if($BiosFile -eq "rom.cab") {
$ReturnBiosUpdate = Start-Process -FilePath .\HpqFlash.exe -ArgumentList "-s -f.\$BiosFile -p.\BIOSPW$i.bin" -PassThru -Wait
} else {
$ReturnBiosUpdate = Start-Process -FilePath .\HPBIOSUPDREC64.exe -ArgumentList "-s -r -b -f.\$BiosFile -p.\BIOSPW$i.bin" -PassThru -Wait
}
$mainExitCode = $ReturnBiosUpdate.ExitCode
# Exit loop when right PSW found and the update executed
If ($mainExitCode -eq 0 -or $mainExitCode -eq 3010) {
Write-ToLog "PSW bin file detected: BIOSPW$i.bin"
Write-ToLog "BIOS Update successful. Exit code:$mainExitCode"
break
}
}
# Copy the HP log files
Write-ToLog "Copy the HP log files"
Copy-Item -Path .\*.log -Destination C:\Windows\CCM\Logs\app
# Enable BitLocker after reboot -> Separate Step in TS - removed
if($BLStatus -eq 1)
{
New-itemProperty -Path HKLM:Software\Microsoft\Windows\CurrentVersion\RunOnce -Name EnableBitlocker -PropertyType String -Value "manage-bde.exe -protectors -enable c:" -Force
Write-ToLog "Enable bitlocker after reboot -> Runonce registry key"
}
Write-ToLog "Script has been finished."
switch ($mainExitCode) {
259
{
Write-ToLog "Exit code: 259 - Invalid CMDLINE parameters."
}
282
{
Write-ToLog "Exit code: 282 - Always flash flag '-a' not found, update will not be performed."
}
3010
{
Write-ToLog "Exit code: 3010 - Reboot required."
}
default
{
Write-ToLog "Exit code: $mainExitCode - Unknown."
}
}
Exit $mainExitCode
}
else
{
Write-ToLog "!!!!Notebook is running on battery. BIOS Update has NOT been done!!!!!"
}