[Bug] Set-DbaPowerPlan fails on non-english language Windows installations
Environmental information
Run below command, paste results below:
#### PowerShell version:
Name Value
---- -----
PSVersion 5.1.17763.1007
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.1007
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
#### dbatools Module version:
Name : dbatools
Path : C:\Program Files\WindowsPowerShell\Modules\dbatools\1.0.100\dbatools.psd1
Version : 1.0.100
LCID Name DisplayName
---- ---- -----------
1031 de-DE Deutsch (Deutschland)
Report
Running Set-DbaPowerPlan on a fresh Windows 2019 Datacenter VM installed with the German language fails to set, because the 'High Performance' plan could not be found by the command.
This is similar to issues #2769 and #245
Host used
- [x] powershell.exe
- [ ] ISE
- [ ] VS Code
- [ ] Other (please specify)
Errors Received
WARNUNG: [10:03:19][Set-DbaPowerPlanInternal] Couldn't find the requested Power Plan 'High Performance' on SQL2019.
Steps to Reproduce
Windows 2019 Datacenter VM in German (presumably any non-english install) Set-DbaPowerPlan -ComputerName {CompterName}
Expected Behavior
Use the GUID values for the PowerPlan info stored in the registry
Actual Behavior
Fails to load the power plan information from the registry because it is searching for the English language names.
Ah, this is by design because we don't know all the different ways to spell it. Our default is English: [string]$PowerPlan = 'High Performance', but you can specify -PowerPlan 'German Phrase'.
Basically, we chose the convenience for a majority of our users (en) users. We can address by removing the default (not so sure), perhaps translating like Get/Test (up for others to do), or adding an example (easy enough). Ultimately, the command is not wrong, there is indeed no plan named High Performance and setting to "High Performance" is not a requirement, only a default.
I'll fix by adding an example. Please let me know the german phrase for High Performance.
Alternatively, Test-DbaPowerPlan -ComputerName sql2017 |Set-DbaPowerPlan can likely be used
Oops that was supposed to be a PR. But this has been fixed in https://github.com/sqlcollaborative/dbatools/commit/37ae326e4b07fd73706e7723d4052ade8598ee92 - i found a german word for high performance from the other issue
Ok, I'm fine with that, just thought it would grab the GUID for "High Performance" and default to that, instead of the string, if that makes sense.
I push most installs to be in English anyway, but with that example to clarify I think we are good to go :)
Yeah, we shouldn't depend on the phrase of a setting because that can be redefined as well with newer versions of the OS.
The GUID for this power setting should be 8C5E7FDA-E8BF-4A96-9A85-A6E23A8C635C, documented here: https://docs.microsoft.com/en-us/windows/win32/power/power-setting-guids
(Which I could have sworn we already did this for something.... 🤔 )
🚧🚨 This issue is being marked as stale due to 90 days of inactivity. If you would like this issue to remain open:
- Verify the issue/bug is reproduced in the latest version of the module
- Verify the environmental info provided is still accurate
- Add any additional steps you followed to reproduce if necessary 🚨🚧 ⌛️ This issue will be closed in 30 days ⌛️
@wsmelton will you open a PR for that or should we close this?
Hi Shawn, can you tell me a litte bit about your plans on this issue?
Seems we have code to support 8C5E7FDA-E8BF-4A96-9A85-A6E23A8C635C in Test but not Set.
I believe this can be solved by
if ($PowerPlan -eq "High Performance") { $PowerPlan = "8C5E7FDA-E8BF-4A96-9A85-A6E23A8C635C" }
We already set the powerplan based on the Guid (see #6679 for all the details - I was involved but forgot about it). I had a look at Get-DbaPowerPlan, Test-DbaPowerPlan and Set-DbaPowerPlan - and I would like to implement some changes to reduce duplicate code. Get-DbaPowerPlan is getting all powerplans from the computer but returning only the active. So Test-DbaPowerPlan needs to get all the plans again because it needs not just the active one but the best practise one as well. So in the first place I would like to add a new output parameter to Get-DbaPowerPlan to also return an array with all other powerplans on the computer. Then we can use this in Test-DbaPowerPlan and Set-DbaPowerPlan without having to most part of Get-DbaPowerPlan again. What do you think?
Sounds good! -All or -List works for me. List is used by Get-ExecutionPolicy but All works too.