Skip to content

Commit

Permalink
Invoke-LenovoBIOSUpdate.ps1 version 1.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
NickolajA committed May 1, 2019
1 parent 53275e1 commit 0bee1ae
Showing 1 changed file with 41 additions and 42 deletions.
83 changes: 41 additions & 42 deletions Operating System Deployment/BIOS/Invoke-LenovoBIOSUpdate.ps1
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
<#
.SYNOPSIS
Invoke Lenovo BIOS Update process.
Invoke Lenovo BIOS Update process.
.DESCRIPTION
This script will invoke the Lenovo BIOS update process for the executable residing in the path specified for the Path parameter.
This script will invoke the Lenovo BIOS update process for the executable residing in the path specified for the Path parameter.
IMPORTANT: This script requires the WinPE-HTA optional component added to the boot image when used during WinPE phase.
.PARAMETER Path
Specify the path containing the WinUPTP or Flash.cmd
Specify the path containing the WinUPTP or Flash.cmd
.PARAMETER Password
Specify the BIOS password if necessary.
Specify the BIOS password if necessary.
.PARAMETER LogFileName
Set the name of the log file produced by the flash utility.
Set the name of the log file produced by the flash utility.
.EXAMPLE
.\Invoke-LenovoBIOSUpdate.ps1 -Path %OSDBIOSPackage01% -Password "BIOSPassword" -LogFileName "LogFileName.log"
.\Invoke-LenovoBIOSUpdate.ps1 -Path %OSDBIOSPackage01% -Password "BIOSPassword" -LogFileName "LogFileName.log"
.NOTES
FileName: Invoke-LenovoBIOSUpdate.ps1
Author: Maurice Daly
Contact: @modaly_it
Author: Maurice Daly / Nickolaj Andersen
Contact: @modaly_it / @NickolajA
Created: 2017-06-09
Updated: 2018-05-08
Updated: 2019-05-01
Version history:
1.0.0 - (2017-06-09) Script created
Expand All @@ -26,7 +34,7 @@
1.0.4 - (2018-05-07) Updated to copy in required OLEDLG.dll where missing in the BIOS package
1.0.5 - (2018-05-08) Updated to cater for varying OS source directory paths
1.0.6 - (2018-12-10) Updated to support 64-bit version of Flash64.cmd
1.0.7 - (2019-05-01) Extended the search for OLEDLG.dll to include X: for when running from WinPE
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param (
Expand Down Expand Up @@ -94,43 +102,38 @@ Process {

# Check for required DLL's
if ((Test-Path -Path (Join-Path -Path $Path -ChildPath "OLEDLG.dll")) -eq $False) {
Write-CMLogEntry -Value "Copying OLEDLG.dll to $Path directory" -Severity 1
Write-CMLogEntry -Value "Copying OLEDLG.dll to $($Path) directory" -Severity 1
if (([string]::IsNullOrEmpty($TSEnvironment.Value("OSDisk"))) -eq $false) {
Copy-Item -Path (Join-Path -path $TSEnvironment.Value("OSDisk") -ChildPath "Windows\System32\OLEDLG.dll") -Destination "$Path\OLEDLG.dll"
Copy-Item -Path (Join-Path -path $TSEnvironment.Value("OSDisk") -ChildPath "Windows\System32\OLEDLG.dll") -Destination "$($Path)\OLEDLG.dll"
}
elseif ((Test-Path -Path "C:\Windows\System32\OLEDLG.dll") -eq $true) {
Copy-Item -Path "C:\Windows\System32\OLEDLG.dll" -Destination "$($Path)\OLEDLG.dll"
}
elseif ((Test-Path -Path C:\Windows\System32\OLEDLG.dll) -eq $true) {
Copy-Item -Path "C:\Windows\System32\OLEDLG.dll" -Destination "$Path\OLEDLG.dll"
elseif ((Test-Path -Path "D:\Windows\System32\OLEDLG.dll") -eq $true) {
Copy-Item -Path "D:\Windows\System32\OLEDLG.dll" -Destination "$($Path)\OLEDLG.dll"
}
elseif ((Test-Path -Path D:\Windows\System32\OLEDLG.dll) -eq $true) {
Copy-Item -Path "D:\Windows\System32\OLEDLG.dll" -Destination "$Path\OLEDLG.dll"
elseif ((Test-Path -Path "X:\Windows\System32\OLEDLG.dll") -eq $true) {
Copy-Item -Path "X:\Windows\System32\OLEDLG.dll" -Destination "$($Path)\OLEDLG.dll"
}
else {
Write-CMLogEntry -Value "Failed to copy DLL file. Abording update process" -Severity 3; exit 1
Write-CMLogEntry -Value "Failed to copy DLL file. Aborting update process" -Severity 3; exit 1
}
}

# WinUPTP bios upgrade utility file name
if (([Environment]::Is64BitOperatingSystem) -eq $true) {
$WinUPTPUtility = Get-ChildItem -Path $Path -Filter "*.exe" -Recurse | Where-Object {
$_.Name -like "WinUPTP64.exe"
} | Select-Object -ExpandProperty FullName
$WinUPTPUtility = Get-ChildItem -Path $Path -Filter "*.exe" -Recurse | Where-Object { $_.Name -like "WinUPTP64.exe" } | Select-Object -ExpandProperty FullName
}
else {
$WinUPTPUtility = Get-ChildItem -Path $Path -Filter "*.exe" -Recurse | Where-Object {
$_.Name -like "WinUPTP.exe"
} | Select-Object -ExpandProperty FullName
$WinUPTPUtility = Get-ChildItem -Path $Path -Filter "*.exe" -Recurse | Where-Object { $_.Name -like "WinUPTP.exe" } | Select-Object -ExpandProperty FullName
}

# Flash CMD upgrade utility file name
if (([Environment]::Is64BitOperatingSystem) -eq $true) {
$FlashCMDUtility = Get-ChildItem -Path $Path -Filter "*.cmd" -Recurse | Where-Object {
$_.Name -like "Flash64.cmd"
} | Select-Object -ExpandProperty FullName
$FlashCMDUtility = Get-ChildItem -Path $Path -Filter "*.cmd" -Recurse | Where-Object { $_.Name -like "Flash64.cmd" } | Select-Object -ExpandProperty FullName
}
else {
$FlashCMDUtility = Get-ChildItem -Path $Path -Filter "*.cmd" -Recurse | Where-Object {
$_.Name -like "Flash.cmd"
} | Select-Object -ExpandProperty FullName
$FlashCMDUtility = Get-ChildItem -Path $Path -Filter "*.cmd" -Recurse | Where-Object { $_.Name -like "Flash.cmd" } | Select-Object -ExpandProperty FullName
}

if ($WinUPTPUtility -ne $null) {
Expand All @@ -147,8 +150,8 @@ Process {
$FlashUtility = $FlashCMDUtility
}

if (!$FlashUtility) {
Write-CMLogEntry -Value "Supported upgrade utility was not found." -Severity 3
if (-not($FlashUtility)) {
Write-CMLogEntry -Value "Supported upgrade utility was not found." -Severity 3; break
}

if ($Password -ne $null) {
Expand All @@ -169,20 +172,16 @@ Process {
$FlashProcess.ExitCode | Out-File -FilePath $LogFilePath

#Get winuptp.log file
$winuptplog = Get-ChildItem -Filter "*.log" -Recurse | Where-Object {
$_.Name -like "winuptp.log"
} -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName
Write-CMLogEntry -Value "winuptp.log file path is $($winuptplog)" -Severity 1
$WinUPTPLog = Get-ChildItem -Filter "*.log" -Recurse | Where-Object { $_.Name -like "winuptp.log" } -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName
Write-CMLogEntry -Value "winuptp.log file path is $($WinUPTPLog)" -Severity 1
$smstslogpath = Join-Path -Path $TSEnvironment.Value("_SMSTSLogPath") -ChildPath "winuptp.log"
Copy-Item -Path $winuptplog -Destination $smstslogpath -Force -ErrorAction SilentlyContinue
Copy-Item -Path $WinUPTPLog -Destination $smstslogpath -Force -ErrorAction SilentlyContinue
}
catch [System.Exception] {
Write-CMLogEntry -Value "An error occured while updating the system BIOS in OS online phase. Error message: $($_.Exception.Message)" -Severity 3; exit 1
}
}
else {
# Used in a later section of the task sequence

# Detect Bitlocker Status
$OSVolumeEncypted = if ((Manage-Bde -Status C:) -match "Protection On") {
Write-Output $True
Expand All @@ -197,12 +196,12 @@ Process {
Manage-Bde -Protectors -Disable C:
}

# Start Bios update process
# Start BIOS update process
try {
Write-CMLogEntry -Value "Running Flash Update - $FlashUtility" -Severity 1
$FlashProcess = Start-Process -FilePath $FlashUtility -ArgumentList "$FlashSwitches" -Passthru -Wait
Write-CMLogEntry -Value "Running Flash Update - $($FlashUtility)" -Severity 1
$FlashProcess = Start-Process -FilePath $FlashUtility -ArgumentList "$($FlashSwitches)" -Passthru -Wait

#Output Exit Code for testing purposes
# Output Exit Code for testing purposes
$FlashProcess.ExitCode | Out-File -FilePath $LogFilePath
}
catch [System.Exception]
Expand Down

0 comments on commit 0bee1ae

Please sign in to comment.