Skip to content

Commit

Permalink
Changes to support older models (Pro 6300)
Browse files Browse the repository at this point in the history
  • Loading branch information
texhex committed Nov 7, 2016
1 parent c5cae55 commit 0124fab
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 50 deletions.
4 changes: 4 additions & 0 deletions BCU-4.0.15.1/_Release Notes.URL
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[InternetShortcut]
URL=https://ftp.hp.com/pub/softpaq/sp74501-75000/sp74840.html
IDList=
HotKey=0
174 changes: 124 additions & 50 deletions BiosSledgehammer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ param(
)

#Script version
$scriptversion="2.41.0"
$scriptversion="2.41.3"

#This script requires PowerShell 4.0 or higher
#requires -version 4.0
Expand Down Expand Up @@ -94,9 +94,6 @@ Set-Variable CurrentPasswordFile "" -Force
#Path to model files
Set-Variable MODELS_PATH "$PSScriptRoot\Models" –option ReadOnly -Force

#Common BIOS value names
Set-Variable ASSET_NAME "Asset Tracking Number" –option ReadOnly -Force
Set-Variable BIOS_VERSION "System BIOS Version" –option ReadOnly -Force

#Common exit code
Set-Variable ERROR_SUCCESS_REBOOT_REQUIRED 3010 –option ReadOnly -Force
Expand Down Expand Up @@ -232,55 +229,97 @@ catch
function Get-BiosValue()
{
param(
[Parameter(Mandatory=$True,ValueFromPipeline=$True)]
[Parameter(Mandatory=$True,ParameterSetName="SingleValue")]
[ValidateNotNullOrEmpty()]
[string]$name,
[string]$Name,

[Parameter(Mandatory=$False,ValueFromPipeline=$True)]
[Parameter(Mandatory=$True,ParameterSetName="NameArray")]
[array]$Names,

[Parameter(Mandatory=$False,ParameterSetName="SingleValue")]
[Parameter(Mandatory=$False,ParameterSetName="NameArray")]
[switch]$Silent=$False
)

if (-not ($Silent)) { write-host "Reading BIOS setting [$name]..." }
$result=$null

$result=""
switch ($PsCmdlet.ParameterSetName)
{
"SingleValue"
{
if (-not ($Silent)) { write-host "Reading BIOS setting [$Name]..." }

try
{
#Try to get a single value
$output=&$BCU_EXE -getvalue $name | Out-String
try
{
#Try to get a single value
$output=&$BCU_EXE -getvalue $Name | Out-String

write-verbose "Read BIOS value: Result from BCU ============="
write-verbose $output.Trim()
write-verbose "=============================================="
write-verbose "Read BIOS value: Result from BCU ============="
write-verbose $output.Trim()
write-verbose "=============================================="

[xml]$xml = $output
[xml]$xml = $output

#This is the actual value
$result = $xml.BIOSCONFIG.SETTING.VALUE.InnerText
#This is the actual value
$result = $xml.BIOSCONFIG.SETTING.VALUE.InnerText

#This should be zero to indicate everything is OK
$returncode= $xml.BIOSCONFIG.SETTING.returnCode
#This should be zero to indicate everything is OK
$returncode= $xml.BIOSCONFIG.SETTING.returnCode

write-verbose "Value: $result"
write-verbose "Return code: $returncode"
write-verbose "Value: $result"
write-verbose "Return code: $returncode"

if ($returncode -ne 0)
if ($returncode -ne 0)
{
if (-not ($Silent)) { write-host " Get-BiosValue failed. Return code was $returncode" }
$result=$null
}
else
{
if (-not ($Silent)) { write-host " Setting read: [$result]" }
}
}
catch
{
if (-not ($Silent)) { write-host " Get-BiosValue failed. Return code was $returncode" }
if ( -not $Silent )
{
write-host " Get-BiosValue failed! Error:"
write-host $error[0]
}
else
{
#even if we are silent, we will at least write the information with verbose
write-verbose " Get-BiosValue failed! Error:"
write-verbose $error[0]
}
$result=$null
}
else
}

"NameArray"
{
write-verbose "Reading BIOS setting using different setting names"

$result=$null

foreach($Name in $Names)
{
if (-not ($Silent)) { write-host " Setting read: [$result]" }
Write-Verbose " Trying using setting name [$Name]..."

$value=Get-BiosValue -Name $Name -Silent:$Silent

if ( $value -ne $null)
{
#We have a result
$result=$value
break
}
}
}
catch
{
if (!($Silent)) { write-host " Get-BiosValue failed! Error:" }
if (!($Silent)) { write-host $error[0] }
$result=$null
}

}

}

return $result
}

Expand Down Expand Up @@ -646,8 +685,10 @@ function Test-BiosPasswordFiles()
[Parameter(Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[string]$PwdFilesFolder
)
)

Set-Variable ASSET_NAME "Asset Tracking Number" –option ReadOnly -Force

Write-HostSection -Start "Determine BIOS Password"

$files=@()
Expand All @@ -667,7 +708,7 @@ function Test-BiosPasswordFiles()
#Start testing
write-host "Testing BIOS passwords..."

$assettag_old=get-biosvalue $ASSET_NAME
$assettag_old=get-biosvalue -Name $ASSET_NAME
write-host "Original Asset Tag [$assettag_old]"

$testvalue=Get-RandomString 14
Expand Down Expand Up @@ -735,7 +776,6 @@ function Test-Environment(){
{
$Make=(Get-CimInstance Win32_ComputerSystem).Manufacturer

#if ( ($Make.StartsWith("HP","CurrentCultureIgnoreCase")) -or ($Make.StartsWith("Hewlett","CurrentCultureIgnoreCase")) )
if ( (Test-String $Make -StartsWith "HP") -or (Test-String $Make -StartsWith "Hewlett") )
{
#All seems to be fine
Expand All @@ -761,20 +801,27 @@ function Test-BiosCommunication()
{
$result=$false

write-host "Trying to read UUID value to test BIOS communication..."
$UUID=Get-BiosValue -Name "Universally Unique Identifier (UUID)" -Silent
write-host "Trying to read UUID to test BIOS communication..."

#At least the ProDesk 600 G1 uses the name "Enter UUID"
#Newer models use "Universally Unique Identifier (UUID)"

$UUIDNames=@("Universally Unique Identifier (UUID)", "Enter UUID")

$UUID=Get-BiosValue -Names $UUIDNames -Silent

if ( -not (Test-String -IsNullOrWhiteSpace $UUID) )
{
write-host " Success"
$result=$true
}
else
{
write-host " Failed"
{
write-host " Failed!"
}

return $result

return $result
}


Expand Down Expand Up @@ -803,7 +850,7 @@ param(
if ( $name -eq $model.ToUpper() )
{
$result=$folder.FullName
write-host " Matching folder found: [$result]"
write-host " Matching folder: [$result]"
break
}
}
Expand All @@ -822,7 +869,7 @@ param(
if ( Test-String $model -Contains $name )
{
$result=$folder.FullName
write-host " Matching folder found: [$result]"
write-host " Matching folder: [$result]"
break
}
}
Expand Down Expand Up @@ -876,6 +923,7 @@ function Copy-FileToTemp()
#Special version for BIOS Version data
#It replaces the first character of a BIOS Version "F" with "1" if necessary. This is needed for older models like 2570p or 6570b:
# http://h20564.www2.hp.com/hpsc/swd/public/detail?sp4ts.oid=5212930&swItemId=ob_173031_1&swEnvOid=4060#tab-history
#Also checks if the version begins with "v" and removes it (e.g. ProDesk 600 G1)
function ConvertTo-VersionFromBIOSVersion()
{
param(
Expand All @@ -886,12 +934,17 @@ function ConvertTo-VersionFromBIOSVersion()
$Text=$Text.Trim()
$Text=$Text.ToUpper()

#if ( $Text.StartsWith("F.") )
if ( Test-String $Text -StartsWith "F." )
{
$Text=$Text.Replace("F.", "1.")
}

#some models report "v" before the version
if ( Test-String $Text -StartsWith "V" )
{
$Text=$Text.Replace("V", "")
}

[version]$curver=ConvertTo-Version -Text $Text -RespectLeadingZeros

return $curver
Expand All @@ -910,6 +963,7 @@ function Get-BIOSVersionDetails()
#N02 Ver. 02.07 01/11/2016
#L83 Ver. 01.34
#SBF13 F.64
#L01 v02.53 10/20/2014

write-verbose "Trying to parse BIOS data [$RawData]"

Expand All @@ -930,7 +984,7 @@ function Get-BIOSVersionDetails()

#now we need to check if we have exactly two or more tokens
#If exactly so, we have FAMILY VERSION
#If more, it can be FAMILY VER VERSION or FAMILY VER VERSION DATE
#If more, it can be FAMILY VER VERSION or FAMILY VER VERSION DATE or FAMILY vVERSION DATE

if ( $tokens.Count -eq 2 )
{
Expand All @@ -939,7 +993,6 @@ function Get-BIOSVersionDetails()
else
{
#we have more than exactly two tokens. Check if the second part is "Ver."
#if ( $tokens[1].Trim().ToLower().StartsWith("ver") )
if ( Test-String ($tokens[1].Trim()) -StartsWith "Ver" )
{
#Use third token as version
Expand All @@ -953,6 +1006,7 @@ function Get-BIOSVersionDetails()

write-verbose " BIOS Version: $versionRaw"


#use special ConvertTo-Version version that replace the F.XX that some models report
[version]$curver=ConvertTo-VersionFromBIOSVersion -Text $versionraw
if ( $curver -eq $null )
Expand Down Expand Up @@ -1884,6 +1938,7 @@ function Remove-File()
Start-Sleep 15
}



$can_start=$false

Expand Down Expand Up @@ -1930,15 +1985,30 @@ function Remove-File()

write-host "Collecting system information..."

$info=Get-CimInstance Win32_ComputerSystem
$Model=$info.Model
$Model=(Get-CimInstance Win32_ComputerSystem).Model
$computername=$env:computername

write-host " "
write-host " Name.........: $computername"
write-host " Model........: $Model"

$BIOSRaw=Get-BiosValue -name $BIOS_VERSION -Silent
########################################
#Retrieve and parse BIOS version

#We could use a direct call to BCU, but this does not work for old models
#because it includes the data like this "L01 v02.53 10/20/2014"
#This breaks the XML parsing from Get-BiosValue because BCU does not escape the slash
#For newer models, this is called "System BIOS Version". For older models, this is "BIOS Version & Date"
#$BIOSVersionNames=@("System BIOS Version", "BIOS Version & Date")
#$BIOSRaw=Get-BiosValue -Names $BIOSVersionNames -Silent

#So we get the data directly from Windows
$BIOSRaw=(Get-CimInstance Win32_Bios).SMBIOSBIOSVersion

#Teststruff
#L01 v02.53 10/20/2014
#68ISB Ver. F.53
#$BIOSRaw="L01 v02.53 10/20/2014"

#replace $NULL in case we were unable to retireve the data
if ( $BIOSRaw -eq $null )
Expand All @@ -1959,6 +2029,10 @@ function Remove-File()
write-host " BIOS Version.: $(Get-VersionTextAndNumerical $BIOSDetails.VersionText $BIOSDetails.Version)"
}


########################################
#Retrieve and parse TPM data

$TPMDetails=Get-TPMDetails
if ( !($TPMDetails.Parsed) )
{
Expand Down

0 comments on commit 0124fab

Please sign in to comment.