From 4a9fca1c6931f21dc64727f7e3943f21d18b4993 Mon Sep 17 00:00:00 2001 From: pasqualm Date: Mon, 7 Mar 2022 09:27:17 +0100 Subject: [PATCH 1/3] Change vallidation method for Lenovo BIOS passwords The operation SetBiosPassword needs a reboot to be efective. After the first execution, all SetBiosPassword operations will fail even if the password is correct until the reboot. This can create a problem if you do multiple Manage-LenovoBiosSettings operations without rebooting between them. The method for checking if the password is correct is changed to trying to set a value with it's current value to try to avoid this situation --- Lenovo/Manage-LenovoBiosSettings.ps1 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Lenovo/Manage-LenovoBiosSettings.ps1 b/Lenovo/Manage-LenovoBiosSettings.ps1 index 9596b6f..ad8f2d8 100644 --- a/Lenovo/Manage-LenovoBiosSettings.ps1 +++ b/Lenovo/Manage-LenovoBiosSettings.ps1 @@ -468,6 +468,9 @@ switch($PasswordSettings.PasswordState) #Ensure passwords are set correctly if($SetSettings -or $SetDefaults) { + #get settings from the machine + $SettingList = $SettingList | Select-Object CurrentSetting | where {$_.CurrentSetting -and ($_.CurrentSetting -NotLike "*ShowOnly*")} | Sort-Object CurrentSetting + if($SvpSet) { Write-LogEntry -Value "Ensure the supplied supervisor password is correct" -Severity 1 @@ -476,8 +479,10 @@ if($SetSettings -or $SetDefaults) { Stop-Script -ErrorMessage "The supervisor password is set, but no password was supplied. Use the SupervisorPassword parameter when a password is set" } + #create test string for the password call + $testValue = $SettingList[-1].CurrentSetting + "," + $SupervisorPassword + ",ascii,us" #Supervisor password set correctly - if($PasswordSet.SetBiosPassword("pap,$SupervisorPassword,$SupervisorPassword,ascii,us").Return -eq "Success") + if(($Interface.SetBiosSetting($testValue)).Return -eq "Success") { Write-LogEntry -Value "The specified supervisor password matches the currently set password" -Severity 1 } @@ -495,8 +500,10 @@ if($SetSettings -or $SetDefaults) { Stop-Script -ErrorMessage "The system management password is set, but no password was supplied. Use the SystemManagementPassword parameter when a password is set" } + #create test string for the password call + $testValue = $SettingList[-1].CurrentSetting + "," + $SystemManagementPassword + ",ascii,us" #System management password set correctly - if($PasswordSet.SetBiosPassword("smp,$SystemManagementPassword,$SystemManagementPassword,ascii,us").Return -eq "Success") + if(($Interface.SetBiosSetting($testValue)).Return -eq "Success") { Write-LogEntry -Value "The specified system management password matches the currently set password" -Severity 1 } From e542514344a1775fb73ccb4c8eca17072b44b715 Mon Sep 17 00:00:00 2001 From: pasqualm Date: Mon, 14 Mar 2022 17:05:38 +0100 Subject: [PATCH 2/3] Update Manage-HPBiosSettings.ps1 Some HP models return the config info with a space in front of them. Change to manage correctly this situation --- HP/Manage-HPBiosSettings.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/HP/Manage-HPBiosSettings.ps1 b/HP/Manage-HPBiosSettings.ps1 index 9c9de1e..e69fa34 100644 --- a/HP/Manage-HPBiosSettings.ps1 +++ b/HP/Manage-HPBiosSettings.ps1 @@ -428,9 +428,9 @@ if($GetSettings) $SplitCount = 0 while($SplitCount -lt $SettingSplit.Count) { - if($SettingSplit[$SplitCount].StartsWith('*')) + if($SettingSplit[$SplitCount].TrimStart().StartsWith('*')) { - $SetValue = ($SettingSplit[$SplitCount]).Substring(1) + $SetValue = ($SettingSplit[$SplitCount].TrimStart()).Substring(1) break } else From f4bb0fbbb2534cb336c031e3993c5d1d2e359ac9 Mon Sep 17 00:00:00 2001 From: pasqualm Date: Tue, 29 Mar 2022 09:36:02 +0200 Subject: [PATCH 3/3] Update Manage-HPBiosSettings.ps1 Some HP models return the config info with a space in front of them. Change to manage correctly this situation when setting values --- HP/Manage-HPBiosSettings.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HP/Manage-HPBiosSettings.ps1 b/HP/Manage-HPBiosSettings.ps1 index e69fa34..061568f 100644 --- a/HP/Manage-HPBiosSettings.ps1 +++ b/HP/Manage-HPBiosSettings.ps1 @@ -225,7 +225,7 @@ Function Set-HPBiosSetting $Count = 0 while($Count -lt $CurrentSettingSplit.Count) { - if($CurrentSettingSplit[$Count].StartsWith('*')) + if($CurrentSettingSplit[$Count].TrimStart().StartsWith('*')) { $CurrentValue = $CurrentSettingSplit[$Count] break