Sign in with
Sign up | Sign in
Closed

Batch File - Delete All Power Plans w/ PowerCfg

Last response: in Applications
Share

Can someone assist me in completing this task?

I have an application that imports a custom power plan and then deletes it and adds the old one back one when the application closes. But as I've been debugging, I'll end the debugging and the closing event won't fire. So the power plans never delete when I do that.

Right now, there's hundreds of power plans and I'm deleting them manually. Since you need a GUID to delete them through the command prompt, I was hoping someone could help me enumerate through the GUIDs and delete them.

Thanks

Best solution

Don't have a Windows System to write this for you right now I'm afraid but take a look at this for a starter on how to iterate through the result of powercfg -list.

I wouldn't run this code verbatim because I have no idea what the results for powercfg -list looks like but you want to do something like:

  1. for /f "skip=2 tokens=2,4 delims=:()" %%G in ('powercfg -list') do (
  2. powercfg -delete %%G
  3. )

Rusting In Peace said:
Don't have a Windows System to write this for you right now I'm afraid but take a look at this for a starter on how to iterate through the result of powercfg -list.

I wouldn't run this code verbatim because I have no idea what the results for powercfg -list looks like but you want to do something like:

  1. for /f "skip=2 tokens=2,4 delims=:()" %%G in ('powercfg -list') do (
  2. powercfg -delete %%G
  3. )


You, sir, are amazing. Although you warned not running it as is, I went ahead and did so. It worked perfectly.

Thanks again, my friend!
Ask the community
!