texhex / BiosSledgehammer

Automated BIOS, ME, TPM firmware update and BIOS settings for HP devices
Apache License 2.0
128 stars 17 forks source link

Communication with BCU fails for systems with PowerShell 4.0 #77

Closed texhex closed 5 years ago

texhex commented 5 years ago

BIOS Sledgehammer fails in the step "Verifying BIOS Configuration Utility (BCU) can communicate with BIOS." with the message:

C:\TEMP\BiosSledgehammer\BiosSledgehammer.ps1 : BCU is unable to communicate with BIOS, can't continue.
        At C:\TEMP\BiosSledgehammer\BiosSledgehammer.ps1:227 char:13

The line in question is 652:

$output = &$BCU_EXE /GetValue:`"$Name`" | Out-String )

This was last changed in commit 7850d426064acf07807d67258819356f46862d34.

It works properly in case the value $PSVersionTable.PSVersion.Major = 5. In case the value $PSVersionTable.PSVersion.Major = 4, the grave accents have to be removed:

$output = &$BCU_EXE /GetValue:"$Name" | Out-String ).

The actual problem is that in PowerShell 4.0, the grace accents seem not to be working as expected, so PowerShell somehow creates several additional parameters and BCU will only read the BIOS value name until the space.

Verifying BIOS Configuration Utility (BCU) can communicate with BIOS.
  Trying to read Universally Unique Identifier (UUID)...VERBOSE: Reading BIOS setting using different setting names
VERBOSE:    Trying using setting name [Universally Unique Identifier (UUID)]...
VERBOSE: &C:xxxx\BiosConfigUtility64.exe /GetValue:"Universally Unique 
Identifier (UUID)" | Out-String
VERBOSE: Read BIOS value: Result from BCU =============
VERBOSE: <BIOSCONFIG Version="" Computername="yyyyy" Date="2018/10/0y" Time="zz:zz:00" UTC="2">
 <SETTING changeStatus="warning" name = "Universally" returnCode="20">
  <VALUE><![CDATA[]]></VALUE>
 </SETTING>
 <Information msg="BCU return value" real="0" translated="0" />
</BIOSCONFIG>
VERBOSE: ==============================================
VERBOSE: Value: 
VERBOSE: Return code: 20

What seems to do the trick is to double escape the quotation marks like this:

$output = &$BCU_EXE /GetValue:""$Name"" | Out-String

It needs to checked if this also works for 5.0 and if also the Set BIOS Value function needs rework.

texhex commented 5 years ago

This change has been done for BCU Get/Set calls, and in my first test calls it works as expected. I need to get a PS 4.0 machine to fully test it; this might take some days.

texhex commented 5 years ago

I got confirmation from a colleague yesterday that all his tests were successful, the BCU calls now work correctly with PS 4.0 and no errors were reported for 5.1. Closing issue.