-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAmdCorePerformanceBoost.ps1
More file actions
421 lines (348 loc) · 13.9 KB
/
Copy pathAmdCorePerformanceBoost.ps1
File metadata and controls
421 lines (348 loc) · 13.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
#requires -Version 5.1
#requires -RunAsAdministrator
<#
.SUMMARY
Manages AMD Core Performance Boost in supported HP Notebooks BIOS firmware.
.DESCRIPTION
Automatically checks whether HP Client Management Script Library (HPCMSL)
is installed. If it is missing, the script updates the Windows PowerShell
package-management components when necessary, installs HPCMSL from the
PowerShell Gallery in a clean process, and then continues.
With no action switch, the script toggles the current BIOS value after an
interactive confirmation. Use -Enable or -Disable to request a specific
state without a confirmation prompt. Add -Silent for unattended execution.
Add -DryRun to preview the BIOS change without writing it.
.NOTES
License: MIT (open source).
Project: https://github.com/ChrispyBacon-dev/AMD-Core-Boost-PS
Run in an elevated Windows PowerShell session on the target HP computer.
Internet access to the PowerShell Gallery is required only when HPCMSL is
not already installed. The installation bootstrap requires 64-bit Windows
PowerShell 5.1. BIOS reads use Get-HPBIOSSetting/Get-HPBIOSSettingValue.
Production testing showed that a complete shutdown and subsequent power-on
are required to apply a successful BIOS change reliably.
#>
[CmdletBinding()]
param(
[switch]$Enable,
[switch]$Disable,
[switch]$Silent,
[switch]$DryRun
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$settingName = 'AMD Core Performance Boost'
function Write-Status {
param([Parameter(Mandatory)][string]$Message)
Write-Information $Message -InformationAction Continue
}
function Get-HighestInstalledModuleVersion {
param([Parameter(Mandatory)][string]$Name)
$module = Get-Module -ListAvailable -Name $Name |
Sort-Object -Property Version -Descending |
Select-Object -First 1
if ($null -eq $module) {
return [version]'0.0'
}
return [version]$module.Version
}
function Invoke-CleanWindowsPowerShell {
param(
[Parameter(Mandatory)][string]$ScriptContent,
[Parameter(Mandatory)][string]$StageName
)
if (-not [Environment]::Is64BitProcess) {
throw 'HPCMSL requires 64-bit Windows PowerShell. Open the 64-bit Windows PowerShell as Administrator and run the script again.'
}
$powerShellExe = Join-Path $env:SystemRoot 'System32\WindowsPowerShell\v1.0\powershell.exe'
if (-not (Test-Path -LiteralPath $powerShellExe)) {
throw "Windows PowerShell 5.1 could not be found at '$powerShellExe'."
}
$temporaryScript = Join-Path $env:TEMP (
'AmdCorePerformanceBoost-{0}-{1}.ps1' -f
$StageName,
([guid]::NewGuid().ToString('N'))
)
try {
$utf8WithoutBom = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllText($temporaryScript, $ScriptContent, $utf8WithoutBom)
& $powerShellExe `
-NoLogo `
-NoProfile `
-NonInteractive `
-ExecutionPolicy Bypass `
-File $temporaryScript
$childExitCode = $LASTEXITCODE
if ($childExitCode -ne 0) {
throw "The '$StageName' installation stage failed with exit code $childExitCode."
}
}
finally {
Remove-Item -LiteralPath $temporaryScript -Force -ErrorAction SilentlyContinue
}
}
function Install-HPCMSLIfMissing {
if (Get-Module -ListAvailable -Name HPCMSL) {
Write-Status 'HPCMSL is already installed.'
return
}
Write-Status 'HPCMSL is not installed. Preparing the PowerShell package manager...'
$minimumPowerShellGetVersion = [version]'2.2.5'
$installedPowerShellGetVersion = Get-HighestInstalledModuleVersion -Name 'PowerShellGet'
if ($installedPowerShellGetVersion -lt $minimumPowerShellGetVersion) {
Write-Status (
'Updating PowerShellGet from version {0} to 2.2.5...' -f
$installedPowerShellGetVersion
)
$bootstrapScript = @'
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
try {
[Net.ServicePointManager]::SecurityProtocol =
[Net.ServicePointManager]::SecurityProtocol -bor
[Net.SecurityProtocolType]::Tls12
$nugetProvider = Get-PackageProvider -Name NuGet -ListAvailable -ErrorAction SilentlyContinue |
Sort-Object -Property Version -Descending |
Select-Object -First 1
if ($null -eq $nugetProvider -or [version]$nugetProvider.Version -lt [version]'2.8.5.201') {
Write-Host 'Installing the NuGet package provider...'
Install-PackageProvider `
-Name NuGet `
-MinimumVersion 2.8.5.201 `
-Force `
-Confirm:$false | Out-Null
}
if (-not (Get-PSRepository -Name PSGallery -ErrorAction SilentlyContinue)) {
Write-Host 'Registering the PowerShell Gallery...'
Register-PSRepository -Default
}
$installedPowerShellGet = Get-Module -ListAvailable -Name PowerShellGet |
Sort-Object -Property Version -Descending |
Select-Object -First 1
if ($null -eq $installedPowerShellGet -or
[version]$installedPowerShellGet.Version -lt [version]'2.2.5') {
Write-Host 'Installing PowerShellGet 2.2.5 and its PackageManagement dependency...'
Install-Module `
-Name PowerShellGet `
-RequiredVersion 2.2.5 `
-Repository PSGallery `
-Scope AllUsers `
-Force `
-AllowClobber `
-Confirm:$false
}
$verifiedPowerShellGet = Get-Module -ListAvailable -Name PowerShellGet |
Where-Object { [version]$_.Version -ge [version]'2.2.5' } |
Sort-Object -Property Version -Descending |
Select-Object -First 1
if ($null -eq $verifiedPowerShellGet) {
throw 'PowerShellGet 2.2.5 was not found after installation.'
}
Write-Host ("PowerShellGet {0} is installed." -f $verifiedPowerShellGet.Version)
exit 0
}
catch {
Write-Error ("PowerShellGet bootstrap failed: {0}" -f $_.Exception.Message)
exit 1
}
'@
Invoke-CleanWindowsPowerShell `
-ScriptContent $bootstrapScript `
-StageName 'PowerShellGet-bootstrap'
}
else {
Write-Status (
'Compatible PowerShellGet version {0} is already installed.' -f
$installedPowerShellGetVersion
)
}
Write-Status 'Installing HPCMSL in a fresh Windows PowerShell session...'
$hpcmslInstallScript = @'
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
try {
[Net.ServicePointManager]::SecurityProtocol =
[Net.ServicePointManager]::SecurityProtocol -bor
[Net.SecurityProtocolType]::Tls12
Import-Module PowerShellGet -MinimumVersion 2.2.5 -Force -ErrorAction Stop
$loadedPowerShellGet = Get-Module -Name PowerShellGet |
Sort-Object -Property Version -Descending |
Select-Object -First 1
if ($null -eq $loadedPowerShellGet -or
[version]$loadedPowerShellGet.Version -lt [version]'2.2.5') {
throw 'A compatible PowerShellGet version could not be loaded in the clean installation session.'
}
if (-not (Get-PSRepository -Name PSGallery -ErrorAction SilentlyContinue)) {
Register-PSRepository -Default
}
$installParameters = @{
Name = 'HPCMSL'
Repository = 'PSGallery'
Scope = 'AllUsers'
Force = $true
AllowClobber = $true
AcceptLicense = $true
Confirm = $false
ErrorAction = 'Stop'
}
Write-Host ("Using PowerShellGet {0}." -f $loadedPowerShellGet.Version)
Install-Module @installParameters
$installedHPCMSL = Get-Module -ListAvailable -Name HPCMSL |
Sort-Object -Property Version -Descending |
Select-Object -First 1
if ($null -eq $installedHPCMSL) {
throw 'HPCMSL was not found after installation.'
}
Write-Host ("HPCMSL {0} was installed successfully." -f $installedHPCMSL.Version)
exit 0
}
catch {
Write-Error ("HPCMSL installation failed: {0}" -f $_.Exception.Message)
exit 1
}
'@
Invoke-CleanWindowsPowerShell `
-ScriptContent $hpcmslInstallScript `
-StageName 'HPCMSL-install'
$installedModule = Get-Module -ListAvailable -Name HPCMSL |
Sort-Object -Property Version -Descending |
Select-Object -First 1
if ($null -eq $installedModule) {
throw 'HPCMSL installation finished, but the module is still not visible in the current session.'
}
Write-Status ("HPCMSL {0} is ready." -f $installedModule.Version)
}
function Write-Result {
param(
[Parameter(Mandatory)][string]$Status,
[Parameter(Mandatory)][string]$Message,
[string]$PreviousValue,
[string]$CurrentValue
)
[pscustomobject]@{
Setting = $settingName
Status = $Status
Message = $Message
PreviousValue = $PreviousValue
CurrentValue = $CurrentValue
ShutdownNeeded = ($Status -eq 'Changed')
}
}
if ($Enable -and $Disable) {
throw 'Use either -Enable or -Disable, not both.'
}
Install-HPCMSLIfMissing
try {
Import-Module HPCMSL -Force -ErrorAction Stop
}
catch {
throw "HPCMSL is installed but could not be imported. $($_.Exception.Message)"
}
if (-not (Get-Command -Name Get-HPBIOSSetting -ErrorAction SilentlyContinue)) {
try {
Import-Module HP.ClientManagement -Force -ErrorAction Stop
}
catch {
throw "The HP.ClientManagement module could not be imported. $($_.Exception.Message)"
}
}
$requiredCommands = @(
'Get-HPBIOSSetting',
'Get-HPBIOSSettingValue',
'Set-HPBIOSSettingValue'
)
foreach ($commandName in $requiredCommands) {
if (-not (Get-Command -Name $commandName -ErrorAction SilentlyContinue)) {
throw "HPCMSL is installed, but the required command '$commandName' is unavailable. Reinstall HPCMSL and try again."
}
}
try {
$setting = Get-HPBIOSSetting -Name $settingName -ErrorAction Stop
$currentValue = [string](Get-HPBIOSSettingValue -Name $settingName -ErrorAction Stop)
$currentValue = $currentValue.Trim().TrimStart('*')
}
catch {
throw "The BIOS setting '$settingName' could not be read. It may not be exposed by this HP model or BIOS version. $($_.Exception.Message)"
}
$statePairs = @(
[pscustomobject]@{ Enabled = 'Checked'; Disabled = 'Unchecked' },
[pscustomobject]@{ Enabled = 'Enable'; Disabled = 'Disable' },
[pscustomobject]@{ Enabled = 'Enabled'; Disabled = 'Disabled' },
[pscustomobject]@{ Enabled = 'On'; Disabled = 'Off' }
)
$currentPair = $statePairs |
Where-Object {
$currentValue -ieq $_.Enabled -or
$currentValue -ieq $_.Disabled
} |
Select-Object -First 1
if ($null -eq $currentPair) {
$reportedProperties = @($setting.PSObject.Properties.Name) -join ', '
throw "The current value '$currentValue' is not a recognized enabled/disabled state for '$settingName'. Returned properties: $reportedProperties. No change was made."
}
$enabledValue = [string]$currentPair.Enabled
$disabledValue = [string]$currentPair.Disabled
if ($Enable) {
$targetValue = $enabledValue
$action = 'enable'
}
elseif ($Disable) {
$targetValue = $disabledValue
$action = 'disable'
}
elseif ($currentValue -eq $disabledValue) {
$targetValue = $enabledValue
$action = 'enable'
}
elseif ($currentValue -eq $enabledValue) {
$targetValue = $disabledValue
$action = 'disable'
}
else {
Write-Result -Status 'Unchanged' -Message 'The current value is not recognized as enabled or disabled. No change was made.' -CurrentValue $currentValue
return
}
if ($currentValue -eq $targetValue) {
Write-Result -Status 'Unchanged' -Message "The setting is already ${action}d." -PreviousValue $currentValue -CurrentValue $currentValue
return
}
if (-not ($Enable -or $Disable) -and -not $Silent -and -not $DryRun) {
Write-Status "Current BIOS value: $currentValue"
Write-Status "Proposed BIOS value: $targetValue"
if (-not $PSCmdlet.ShouldContinue(
"Do you want to $action '$settingName'?",
'Confirm BIOS change')) {
Write-Result -Status 'Cancelled' -Message 'No BIOS change was made.' -PreviousValue $currentValue -CurrentValue $currentValue
return
}
}
if ($DryRun) {
Write-Result -Status 'DryRun' -Message "The setting would be changed to '$targetValue'." -PreviousValue $currentValue -CurrentValue $currentValue
return
}
$setResult = Set-HPBIOSSettingValue -Name $settingName -Value $targetValue
$updatedValue = [string](Get-HPBIOSSettingValue -Name $settingName -ErrorAction Stop)
$updatedValue = $updatedValue.Trim().TrimStart('*')
if ($updatedValue -ne $targetValue) {
throw "The BIOS change did not verify. Current reported value: $updatedValue. Command result: $setResult"
}
Write-Result -Status 'Changed' -Message 'The BIOS setting was updated successfully. Shut down Windows completely, then power the computer on again to apply it.' -PreviousValue $currentValue -CurrentValue $updatedValue
if (-not ($Enable -or $Disable) -and -not $Silent) {
$shutdownChoices = [System.Management.Automation.Host.ChoiceDescription[]]@(
(New-Object -TypeName System.Management.Automation.Host.ChoiceDescription -ArgumentList ('&Shut down now', 'Shut down Windows in 10 seconds.')),
(New-Object -TypeName System.Management.Automation.Host.ChoiceDescription -ArgumentList ('Shut down &later', 'Leave Windows running so you can shut it down manually.'))
)
$shutdownChoice = $Host.UI.PromptForChoice(
'Complete shutdown required',
'The BIOS change requires a complete shutdown. Shut down Windows in 10 seconds?',
$shutdownChoices,
1
)
if ($shutdownChoice -eq 0) {
Write-Status 'Windows will shutdown in 10 seconds. Power the computer on again to apply the BIOS change.'
& shutdown.exe /s /t 10
}
else {
Write-Status 'Shutdown postponed. Shutdown Windows completely, then power the computer on again to apply the BIOS change.'
}
}