Question: I have created scheduled tasks on both a Vista and Win7 machine which wake up the machine if it is currently in a sleep state. However, if the task takes longer than the power settings are configured on the machine, the machine will return to a sleep state. It looks like [this](http://www.catfood.net/blog/2008/12/prevent-sleep-during-scheduled-tasks.asp) utility might be a solution, but I was wondering if there were other options.

Does anyone know of a powershell command or other utility that will prevent my machine from going into a sleep state while a task is running?

Answer: 
The simplest way I have found to easily switch power modes to manage the machines ability to manage power is by defining **Power Schemes**. You just go into control panel and create any new power schemes or edit the existing existing predefined schemes. Setup a scheme for how you want the machine to behave normally where it does go to sleep when allowed. For example, on my Windows 7 machines I just edit the predefined "Balanced" power scheme for this. Then edit or create a scheme where the machine runs at full speed / power 100% of the time and is not allowed to sleep. Again, I just edit the existing "High Performance" power scheme and configure it that way. Then once these power schemes are defined you can easily script the mode the machine is running in using the **POWERCFG.EXE** command line utility. 

Pop open a command line window and run:

```
powercfg -list

```

... when that runs, you should get a list of all of the machines defined power schemes along with the corresponding GUID value that you will need to note. Then to switch the machine from one power scheme to another, I have a simple batch file / script that I can run which passes the GUID for the scheme I want the machine to be running in. This way in my scheduled tasks and other tools, I can just call one of my scripts to keep the machine running without hibernating or at full speed. The batch file just uses powercfg.exe with the setactive switch to pick which power scheme I want. So this will look something like:

```
powercfg -setactive 381b4222-f694-41f0-9685-ff5bb260df2e

```

Just note that the last part is the GUID for your machine that you get by using the above list command.
There should be a checkbox in the options for scheduling a task. I don't have Win 7 in front of me at the moment so I can't say exactly where, just that I've used it before.