MSEndpointMgr / ConfigMgr

Microsoft Endpoint Configuration Manager scripts and tools
633 stars 281 forks source link

Invoke-LenovoBIOSUpdate does not work with new ThinkPad models #359

Open MrMortensen opened 1 year ago

MrMortensen commented 1 year ago

I have found out that the powershell script for Lenovo BIOS update, Invoke-LenovoBIOSUpdate.ps1, does work on some new ThinkPad models. That is the models: ThinkPad T14 Gen 3 & 4 ThinkPad P14s Gen 3 & 4 ThinkPad T16 Gen 1 & 2 ThinkPad P16s Gen 1 & 2 Because the WinUPTP64.exe (used for 64-bit OS) doesn't exists in the BIOS update package. There is only WinUPTP.exe version. This update that first check for WinUPTP64.exe and then WinUPTP.exe will solve the problem.

Line 127:

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
    if (!($WinUPTPUtility)) {
        $WinUPTPUtility = Get-ChildItem -Path $Path -Filter "*.exe" -Recurse | Where-Object { $_.Name -like "WinUPTP.exe" } | Select-Object -ExpandProperty FullName
    }
}
else {
    $WinUPTPUtility = Get-ChildItem -Path $Path -Filter "*.exe" -Recurse | Where-Object { $_.Name -like "WinUPTP.exe" } | Select-Object -ExpandProperty FullName
}
baardhermansen commented 1 year ago

Always filter left whenever you can and don't use -Like if you don't intend to use wildcard.

Simplified version:

if ([Environment]::Is64BitOperatingSystem) {
    $WinUPTPUtility = Get-ChildItem -Path $Path -Filter "WinUPTP64.exe" -Recurse | Select-Object -ExpandProperty FullName
}

if (!($WinUPTPUtility)) {
    $WinUPTPUtility = Get-ChildItem -Path $Path -Filter "WinUPTP.exe" -Recurse | Select-Object -ExpandProperty FullName
}
MrMortensen commented 1 year ago

There is an update, the first solution only works when Windows is installed. There has been has been added the file WinPEUPTB.exe for updating BIOS via WinPE. The code should be updated to the following:

if ($TSEnvironment.Value("SMSTSinWinPE") -eq $true) { $WinUPTPUtility = Get-ChildItem -Path $Path -Filter "*.exe" -Recurse | Where-Object { $.Name -like "WINPEUPTP.exe" } | Select-Object -ExpandProperty FullName }

if (([Environment]::Is64BitOperatingSystem) -eq $true -and !($WinUPTPUtility)) { $WinUPTPUtility = Get-ChildItem -Path $Path -Filter "*.exe" -Recurse | Where-Object { $_.Name -like "WinUPTP64.exe" } | Select-Object -ExpandProperty FullName }

if (!($WinUPTPUtility)) { $WinUPTPUtility = Get-ChildItem -Path $Path -Filter "*.exe" -Recurse | Where-Object { $_.Name -like "WinUPTP.exe" } | Select-Object -ExpandProperty FullName }

gooooba commented 1 year ago

Thank you, but it didn't work in PE. Two underscore's were were missing(typo I guess...). The code below works(tested).

if ($TSEnvironment.Value("_SMSTSinWinPE") -eq $true) {
$WinUPTPUtility = Get-ChildItem -Path $Path -Filter "*.exe" -Recurse | Where-Object { $_.Name -like "WINPEUPTP.exe" } | Select-Object -ExpandProperty FullName
}

if (([Environment]::Is64BitOperatingSystem) -eq $true -and !($WinUPTPUtility)) {
$WinUPTPUtility = Get-ChildItem -Path $Path -Filter "*.exe" -Recurse | Where-Object { $_.Name -like "WinUPTP64.exe" } | Select-Object -ExpandProperty FullName
}

if (!($WinUPTPUtility)) {
$WinUPTPUtility = Get-ChildItem -Path $Path -Filter "*.exe" -Recurse | Where-Object { $_.Name -like "WinUPTP.exe" } | Select-Object -ExpandProperty FullName
}