所以,我一直在爲HP Bios的腳本編寫一些任務。有一個稱爲HPBIOS_BIOSSettingInterface的Wmi命名空間。它基本上有一個特殊的SetBIOSSetting(「Property」,「Value」,「CurrentSetupPassword」)。以前的HP系統只支持KBD編碼,我編寫了一個函數來編碼帶有KDB值的字符串,可以在這裏找到:http://thomas-malkewitz.webnode.com/news/convert-tokbdstring/,並且使用此編碼設置設置密碼值時,它可以工作,但是對於新的HP,它只支持UTF-16(我無法找到它的大或小,但都嘗試過)。這樣做時我不斷收到錯誤。所以,我的問題是,我如何編碼一個字符串值並將其傳遞給此方法。我無法弄清楚我的生活。這裏是我的功能:Powershell編碼將值傳遞給WmiMethod
<#
.Synopsis
Sets the Setup Password on an HP Bios.
.DESCRIPTION
This function can be used to set a password on the Bios, it can also be used to clear the password, the current password is needed to change the value.
If a new value is being set, and not cleared, it must be between 8 and 30 characters.
.EXAMPLE
Set-HpSetupPassword -NewSetupPassword "MyNewPassword"
.EXAMPLE
Set-HpSetupPassword -ComputerName "mycomputer.mydomain.org" -NewSetupPassword " " -CurrentSetupPassword "MyCurrentPassword"
.EXAMPLE
Set-HpSetupPassword -NewSetupPassword "MyNewSetupPassword" -CurrentSetupPassword "MyCurrentPassword"
.LINKS
https://github.com/necromorph1024/HPTpmAndBitLocker
#>
function Set-HpSetupPassword
{
[CmdletBinding()]
[OutputType([void])]
Param
(
# ComputerName, Type string, System to set Bios Setup Password.
[Parameter(Mandatory=$false,
Position=0)]
[string]
$ComputerName=$env:COMPUTERNAME,
# NewSetupPassword, Type string, The value of the password to be set. The password can be cleared by using a space surrounded by double quotes, IE: " ".
[Parameter(Mandatory=$true,
Position=1)]
[string]
$NewSetupPassword,
# CurrentSetupPassword, Type string, The value of the current setup password.
[Parameter(Mandatory=$false,
Position=2)]
[AllowEmptyString()]
[string]
$CurrentSetupPassword
)
Begin
{
if (!(Test-Connection -ComputerName $ComputerName -Quiet -Count 2))
{
throw "Unable to connect to $ComputerName. Please ensure the system is available."
}
try
{
$manufacturer = Get-WmiObject -Class Win32_ComputerSystem -Namespace "root\CIMV2" -Property "Manufacturer" -ComputerName $ComputerName -ErrorAction Stop
if ($manufacturer.Manufacturer -ne "Hewlett-Packard")
{
throw "Computer Manufacturer is not of type Hewlett-Packard. This cmdlet can only be used on Hewlett-Packard systems."
}
}
catch
{
throw "Unable to connect to the Win32_ComputerSystem WMI Namespace, verify the system is avaialbe and you have the permissions to access the namespace."
}
}
Process
{
if (-not([String]::IsNullOrWhiteSpace($NewSetupPassword)))
{
if (($NewSetupPassword.Length -lt 8) -or ($NewSetupPassword.Length -gt 30))
{
throw "The Password Values must be be between 8 and 30 characters if not clearing the password."
}
}
$hpBios = Get-WmiObject -Class HP_BiosSetting -Namespace "root\HP\InstrumentedBIOS" -ComputerName $ComputerName -ErrorAction Stop
$hpBiosSettings = Get-WmiObject -Class HPBIOS_BIOSSettingInterface -Namespace "root\HP\InstrumentedBIOS" -ComputerName $ComputerName -ErrorAction stop
if (($hpBios | Where-Object { $_.Name -eq "Setup Password"}).SupportedEncoding -eq "kbd")
{
if (-not([String]::IsNullOrEmpty($NewSetupPassword)))
{
$NewSetupPassword="<kbd/>"+(Convert-ToKbdString -UTF16String $NewSetupPassword)
}
if (-not([String]::IsNullOrEmpty($CurrentSetupPassword)))
{
$CurrentSetupPassword="<kbd/>"+(Convert-ToKbdString -UTF16String $CurrentSetupPassword)
}
}
$hpBiosSettings.SetBIOSSetting("Setup Password",$NewSetupPassword,$CurrentSetupPassword)
}
}
它使返回6是拒絕訪問,這是我與舊的BIOS讓,直到我創建了一個轉換,KbdString方法。我知道我使用的密碼是正確的。但我不知道什麼編碼發送到WmiMethod。感謝您的幫助
這裏是GitHub庫:https://github.com/necromorph1024/HpTpmAndBitLocker
你知道,這就是我的想法,現在我更加沮喪,因爲它應該與$ hpBiosSettings.SetBIOSSettings(「設置密碼」,「MyNewPassword」,「MyCurrentPassword」)一起工作,這讓我發瘋。謝謝。 – dotps1