Skip to content

Instantly share code, notes, and snippets.

@SMSAgentSoftware
Created September 12, 2022 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SMSAgentSoftware/45aac51d96ff40251855de62a1f12fdf to your computer and use it in GitHub Desktop.
Save SMSAgentSoftware/45aac51d96ff40251855de62a1f12fdf to your computer and use it in GitHub Desktop.
Sets the initial password for HP BIOS
##########################
## SET HP BIOS PASSWORD ##
##########################
#region SetBIOSPassword
Write-Output "Setting BIOS password"
# Check if HP BIOS Password is set
Try
{
$HPBIOSClassExists = Get-CimClass -Namespace ROOT\HP\InstrumentedBIOS -ClassName HP_BIOSSettingInterface -ErrorAction Stop
}
Catch
{
Write-Output "HP_BIOSSettingInterface WMI class does not exist. No need to set the HP BIOS password."
}
If ($HPBIOSClassExists)
{
$HPPwdSet = Get-CimInstance -Namespace ROOT\HP\InstrumentedBIOS -Query "Select * from HP_BIOSPassword Where Name='Setup Password' and IsSet=0" -ErrorAction SilentlyContinue
If ($HPPwdSet)
{
Write-Output "HP BIOS Password already set: NO"
$Base64Pwd = "SABQAF8BHU89KKKBjAAANQAhAA=="
$Bytes = [System.Convert]::FromBase64String($Base64Pwd)
$NewPassword = [System.Text.Encoding]::Unicode.GetString($Bytes)
$CurrentPassword = "<utf-16/>"
$EncodedPassword = "<utf-16/>$NewPassword"
$SettingName = "Setup Password"
$CimInstance = Get-CimInstance -Namespace ROOT\HP\InstrumentedBIOS -ClassName HP_BIOSSettingInterface
$Params = @{
Name = $SettingName
Value = $EncodedPassword
Password = $CurrentPassword
}
$Result = Invoke-CimMethod -InputObject $CimInstance -MethodName SetBIOSSetting -Arguments $params
Switch ($Result.Return) {
0 {$ResultDescription = "Success"}
1 {$ResultDescription = "Not Supported"}
2 {$ResultDescription = "Unknown Error"}
3 {$ResultDescription = "Timeout"}
4 {$ResultDescription = "Failed"}
5 {$ResultDescription = "Invalid Parameter"}
6 {$ResultDescription = "Access Denied"}
32768 {$ResultDescription = "Security Policy is violated"}
32769 {$ResultDescription = "Security Condition is not met"}
32770 {$ResultDescription = "Security Configuration"}
default {$ResultDescription = "Unknown"}
}
If ($ResultDescription -ne "Success")
{
Write-Error "Failed to set HP BIOS password: $ResultDescription"
}
else
{
Write-Output "HP BIOS password has been set"
}
}
Else
{
Write-Output "HP BIOS Password is either already set or the instance isn't present in WMI"
}
}
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment