Decaf caffeine: Keeping Your PC Awake with PowerShell

If you’re like me and find yourself working odd hours—especially over the weekend—you know how frustrating it can be when your PC decides to take a nap every few minutes. I often need to glance at my screen to check logs, monitor tasks, or respond to messages, and having to log back in every five minutes is a productivity killer.

That’s why I built a simple PowerShell script that acts as a native replacement for the popular Caffeine software. For those unfamiliar, Caffeine is a lightweight utility that simulates a keypress to keep your machine awake. It’s handy—but many corporate environments block third-party utilities like it, leaving you stuck with default sleep settings.

Why PowerShell?

PowerShell is built into Windows, making it a perfect candidate for scripting solutions that bypass third-party restrictions. My script uses a loop to simulate activity at regular intervals, preventing the system from locking or going to sleep. No installs, no admin rights, no fuss.

Here’s a simplified version of what it does.

1.  Open your PowerShell profile:
    

Notepad $profile 
 
If you get an error saying the profile doesn't exist you can create one using:
    
New-Item -ItemType File -Path $PROFILE -Force

2.  Paste the following code in to the document and save:

function wake{
$wshell = New-Object -ComObject wscript.shell;
"Press CTRL+C to cancel."
while ($true) {
$wshell.SendKeys('+')
Sleep 60
}
}

3.  Close and re open the Powershell terminal.

4.  Now type "wake" and Enter when you want to keep the screen awake.



This toggles the Num Lock key every one minute—just enough to keep Windows awake without interfering with your workflow.

Real-World Use Case

On weekends, I’m often multitasking—coding, testing, and checking in on long-running jobs. I don’t want to keep logging in every time I walk away for a few minutes. With this script running in the background, I can glance at my screen and get back to work instantly.

It’s also a lifesaver in environments where Caffeine is blocked by group policy or endpoint protection. Since this script runs natively in PowerShell, it flies under the radar while still doing the job.

Important Disclaimer

This script is designed for personal use in secure environments. Do not use it in an public setting—leaving your machine unlocked can expose sensitive data and allow unauthorized access. 

Always prioritise security over convenience.

Has this helped? Consider buying me a coffee?Has this helped? Consider buying me a coffee?

Has this helped? Consider buying me a coffee?

Comments