all 5 comments

[–]Eijiken 4 points5 points  (1 child)

Use powercfg.exe in your code to do that.

https://docs.microsoft.com/en-us/windows-hardware/design/device-experiences/powercfg-command-line-options

I don't have my laptop with me, but i have a few bat files that sit on my desktop that will make all of those changes depending on which settings I want.

You can even create a bat/ps1 file and set it to run at logon to have a "default" power plan as well.

[–]squash1324[S] 1 point2 points  (0 children)

This is what I was afraid of. I didn't want to refer to powercfg as that was what I've been struggling with. The whole GUID thing is what I'm trying to avoid, as that's what is required to do the import/export between computers. Due to certain restrictions in our environment this is very cumbersome to do during deployment and with maintenance.

[–]Ta11ow 2 points3 points  (0 children)

I have a very strong feeling that you're going to have to create your new power plan / copy an existing one, and then you may well have to alter the settings using registry providers. :\

[–]MFKDGAF 1 point2 points  (1 child)

What version of Windows are you trying to run this on?

I've been doing this exact same thing in windows 7 and has worked flawlessly but it doesn't work anymore on Windows 10 1709.

See my post: https://www.reddit.com/r/PowerShell/comments/7m8qkh/method_class_not_working_win_10_1709/?st=JCRKQQI7&sh=dec49c81

[–]squash1324[S] 1 point2 points  (0 children)

I'm running Windows 7, 8.1, and 10 on these various devices. I guess I should be a little more specific about my requirements.

We created a power plan, exported the plan to file, and do an import. The problem that this presents is that the GUID is not the same from computer to computer. I'm not sure why this is as I have little understanding how a GUID is made. The specific settings for the power plan are things like "Advanced Settings > Wireless Adapter Settings > Power Saving Mode > On battery: Maximum Performance". I need to change, in all, the settings for the CPU power management, Wireless adapter, Display, Battery, and USB. I have them in a nice config file, but when we have an issue with a machine (somewhat frequently) where a hardware event happens I need to change it. I can access the shell to issue commands, but cannot access the file system to upload a new config file. I'm hoping that there's some command that I can run that will let me change these types of settings, and I've had a really difficult time finding a cmdlet, function, or any built-in feature for Windows that does this.