Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .SYNOPSIS
- 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.
- .PARAMETER Path
- Specify the path containing the WinUPTP or Flash.cmd
- .PARAMETER Password
- Specify the BIOS password if necessary.
- .PARAMETER LogFileName
- Set the name of the log file produced by the flash utility.
- .EXAMPLE
- .\UpdateLenovoBIOSUpdate.ps1 -Path %LenovoBIOSFiles% -LogFileName "LogFileName.log"
- .NOTES
- FileName: UpdateLenovoBIOSUpdate.ps1
- Created: 2018-06-19
- Adapted from Invoke-LenovoBios.ps1 from Maurice Daly
- Version history:
- 1.0.0 - (2018-06-19) Script created
- 1.0.1 - (2018.06.26) Updated testing to try and make sure 32-bit updates didn't happen in WinPE
- #>
- [CmdletBinding(SupportsShouldProcess = $true)]
- param (
- [parameter(Mandatory = $true, HelpMessage = "Specify the path containing the Flash64W.exe and BIOS executable.")]
- [ValidateNotNullOrEmpty()]
- [string]$Path,
- [parameter(Mandatory = $false, HelpMessage = "Specify the BIOS password if necessary.")]
- [ValidateNotNullOrEmpty()]
- [string]$Password,
- [parameter(Mandatory = $false, HelpMessage = "Set the name of the log file produced by the flash utility.")]
- [ValidateNotNullOrEmpty()]
- [string]$LogFileName = "LenovoFlashBiosUpdate.log"
- )
- Begin
- {
- # Load Microsoft.SMS.TSEnvironment COM object
- try
- {
- $TSEnvironment = New-Object -ComObject Microsoft.SMS.TSEnvironment -ErrorAction Stop
- }
- catch [System.Exception] {
- Write-Warning -Message "Unable to construct Microsoft.SMS.TSEnvironment object"
- }
- }
- Process
- {
- # Functions
- function Write-CMLogEntry
- {
- param (
- [parameter(Mandatory = $true, HelpMessage = "Value added to the log file.")]
- [ValidateNotNullOrEmpty()]
- [string]$Value,
- [parameter(Mandatory = $true, HelpMessage = "Severity for the log entry. 1 for Informational, 2 for Warning and 3 for Error.")]
- [ValidateNotNullOrEmpty()]
- [ValidateSet("1", "2", "3")]
- [string]$Severity,
- [parameter(Mandatory = $false, HelpMessage = "Name of the log file that the entry will written to.")]
- [ValidateNotNullOrEmpty()]
- [string]$FileName = "Invoke-LenovoBIOSUpdate.log"
- )
- # Determine log file location
- $LogFilePath = Join-Path -Path $Script:TSEnvironment.Value("_SMSTSLogPath") -ChildPath $FileName
- # Construct time stamp for log entry
- $Time = -join @((Get-Date -Format "HH:mm:ss.fff"), "+", (Get-WmiObject -Class Win32_TimeZone | Select-Object -ExpandProperty Bias))
- # Construct date for log entry
- $Date = (Get-Date -Format "MM-dd-yyyy")
- # Construct context for log entry
- $Context = $([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)
- # Construct final log entry
- $LogText = "<![LOG[$($Value)]LOG]!><time=""$($Time)"" date=""$($Date)"" component=""LenovoBIOSUpdate.log"" context=""$($Context)"" type=""$($Severity)"" thread=""$($PID)"" file="""">"
- # Add value to log file
- try
- {
- Out-File -InputObject $LogText -Append -NoClobber -Encoding Default -FilePath $LogFilePath -ErrorAction Stop
- }
- catch [System.Exception] {
- Write-Warning -Message "Unable to append log entry to Invoke-LenovoBIOSUpdate.log file. Error message: $($_.Exception.Message)"
- }
- }
- cd $Path
- # Write log file for script execution
- Write-CMLogEntry -Value "Initiating script to determine flashing capabilities for Lenovo BIOS updates" -Severity 1
- ## DETERMINE BIOS UPDATE METHOD
- if (Test-Path "$Path\WinUPTP*.exe")
- {
- Write-CMLogEntry -Value "Using WinUTPT BIOS update method" -Severity 1
- if (Test-Path "$Path\WinUPTP64.exe")
- {
- Write-CMLogEntry -Value "Using WinUTPT 64-bit" -Severity 1
- $FlashSwitches = " /S"
- $FlashUtility = "$Path\\WinUPTP64.exe"
- }
- else
- {
- Write-CMLogEntry -Value "Using WinUTPT 32-bit. Setting TS Variable for full-OS update of BIOS" -Severity 1
- $FlashSwitches = " /S"
- $FlashUtility = "$Path\\WinUPTP.exe"
- $TSEnvironment.Value("BIOSFULLOS") = $true
- }
- }
- if (Test-Path "$Path\Flash*.cmd")
- {
- Write-CMLogEntry -Value "Using Flash BIOS update method" -Severity 1
- if (Test-Path "$Path\Flash64.cmd")
- {
- Write-CMLogEntry -Value "Using Flash 64-bit CMD file" -Severity 1
- $FlashSwitches = " /quiet /sccm /ign"
- $FlashUtility = "$Path\\Flash64.cmd"
- $TSEnvironment.Value("BIOSSHUTDOWN") = $true
- }
- else
- {
- Write-CMLogEntry -Value "Using Flash 32-bit CMD file. Setting TS Variable for full-OS update of BIOS" -Severity 1
- $FlashSwitches = " /quiet /sccm /ign"
- $FlashUtility = "$Path\\Flash.cmd"
- $TSEnvironment.Value("BIOSFULLOS") = $true
- $TSEnvironment.Value("BIOSSHUTDOWN") = $true
- }
- }
- # Set log file location
- $LogFilePath = Join-Path -Path $TSEnvironment.Value("_SMSTSLogPath") -ChildPath $LogFileName
- ## BIOS UPDATE PROCESS
- ## Apply 64-bit updates in WinPE
- if (($TSEnvironment -ne $null) -and ($TSEnvironment.Value("_SMSTSinWinPE") -eq $true) -and ($TSEnvironment.Value("BIOSFULLOS") -ne $true))
- {
- try
- {
- # Start flash update process
- $FlashProcess = Start-Process -FilePath $FlashUtility -ArgumentList "$FlashSwitches" -Passthru -Wait
- #Output Exit Code for testing purposes
- $FlashProcess.ExitCode | Out-File -FilePath $LogFilePath
- #Get winuptp.log file
- if (Test-Path "$Path\WinUPTP64.exe")
- {
- $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
- }
- }
- 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
- }
- }
- ##Apply 32-bit Updates in Windows
- if (($TSEnvironment -ne $null) -and ($TSEnvironment.Value("_SMSTSinWinPE") -ne $true) -and ($TSEnvironment.Value("BIOSFULLOS") -eq $true))
- {
- # Used in a later section of the task sequence
- # Detect Bitlocker Status
- $OSVolumeEncypted = if ((Manage-Bde -Status C:) -match "Protection On") { Write-Output $True }
- else { Write-Output $False }
- # Supend Bitlocker if $OSVolumeEncypted is $true
- if ($OSVolumeEncypted -eq $true)
- {
- Write-CMLogEntry -Value "Suspending BitLocker protected volume: C:" -Severity 1
- Manage-Bde -Protectors -Disable C:
- }
- # Start Bios update process
- try
- {
- Write-CMLogEntry -Value "Running Flash Update - $FlashUtility" -Severity 1
- $FlashProcess = Start-Process -FilePath $FlashUtility -ArgumentList "$FlashSwitches" -Passthru -Wait
- #Output Exit Code for testing purposes
- $FlashProcess.ExitCode | Out-File -FilePath $LogFilePath
- }
- catch [System.Exception]
- {
- Write-Warning -Message "An error occured while updating the system bios. Error message: $($_.Exception.Message)"; exit 1
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement