DIY WORKAROUND

PowerShell Script to Keep Teams Active

A working script that stops the 5-minute Away timer — and the four honest ways it breaks that nobody mentions before you've already copy-pasted it.

Published August 13, 2026 · By · 7 min read
QUICK ANSWER

A PowerShell loop that sends a harmless F15 keystroke every couple of minutes keeps Microsoft Teams' presence detector satisfied, because Teams treats a synthetic keypress the same as a real one and resets its ~5-minute inactivity timer. It's free and takes two minutes to set up.

The catch: it only works while you're logged in and unlocked. Lock your screen, close the lid, or restart, and the script either stops running or its keystrokes get silently dropped — Teams flips you to Away exactly as if the script didn't exist.

The Script

This is the standard approach: System.Windows.Forms.SendKeys sends a synthetic F15 keypress on a timer. F15 is the deliberate choice — almost no physical keyboard has one, so it can't trigger a shortcut, type a character, or interfere with whatever you're doing. Teams still registers it as input.

Add-Type -AssemblyName System.Windows.Forms while ($true) { [System.Windows.Forms.SendKeys]::SendWait("{F15}") Start-Sleep -Seconds 120 }

Save that as keep-teams-active.ps1. It sends one F15 keystroke every two minutes — comfortably inside Teams' ~5-minute window — until you close the PowerShell window, log out, or the machine restarts. Run it by right-clicking the file and choosing Run with PowerShell, or launch it without a visible window:

powershell.exe -WindowStyle Hidden -File "C:\Scripts\keep-teams-active.ps1"

First-time setup: if PowerShell blocks the script from running, it's the default execution policy, not a problem with the script itself. Run Set-ExecutionPolicy -Scope CurrentUser RemoteSigned once in an elevated PowerShell window to allow locally-saved scripts, then try again.

Run It Automatically at Login

A script only lasts until the next reboot unless you register it as a Scheduled Task. This makes it start hidden, every time you sign in, without you having to remember to launch it:

$action = New-ScheduledTaskAction -Execute "powershell.exe" ` -Argument "-WindowStyle Hidden -File `"C:\Scripts\keep-teams-active.ps1`"" $trigger = New-ScheduledTaskTrigger -AtLogOn Register-ScheduledTask -TaskName "KeepTeamsActive" -Action $action -Trigger $trigger -RunLevel Highest

Run that block once in PowerShell (as your own user — admin rights aren't required for the script itself, only if your account needs elevation to register scheduled tasks). From then on, the keep-active loop starts automatically every time you log in, and keeps running quietly in the background.

The Four Ways It Breaks

Every gist and StackOverflow answer that hands you this script skips the part where it stops working. In order of how often each one actually bites:

01 — THE BIG ONE

It does nothing once your screen is locked

Windows blocks synthetic input — SendKeys included — from reaching a locked session, by design, for security reasons. The script keeps running in the background, but every F15 it sends is silently swallowed. Lock your PC for a coffee break or a meeting elsewhere in the building, and you go Away exactly as if you'd never run the script.

02

It doesn't survive a reboot on its own

A raw .ps1 running in a window or background job dies with the session. The Scheduled Task above fixes this for "starts again automatically" — but it still needs you logged in and unlocked to actually do anything, which brings you straight back to problem 01.

03

It can get flagged on a managed device

A background PowerShell process sending synthetic keystrokes on an infinite loop is a pattern some EDR and endpoint-monitoring tools watch for — the same technique shows up in real input-simulation malware. On a personal laptop it's a non-issue. On a corporate device with Conditional Access or endpoint monitoring, it can trigger an alert, or get silently killed by policy. Check with IT before running it on a managed machine.

04

It only works while the machine is powered on

Sleep, hibernate, or a shutdown all stop the loop the same way a lock screen does — the difference is only in how obviously it fails. If your goal is to actually close the laptop and go somewhere, a script running on that laptop can't help you.

PowerShell Script vs. the Alternatives

None of the DIY options survive a locked screen, which is the scenario that actually matters for most people — stepping away, closing the lid, or having your PC auto-lock on a security policy. Here's how the three real options compare:

MethodCostSurvives lock screen?Survives reboot?IT/AV risk
PowerShell script (this page)FreeNoOnly with a Scheduled Task, and still needs unlockPossible on managed devices
Hardware mouse jiggler$15–30NoYes (plug-and-play)Low
Cloud presence servicePaid subscriptionYesYesNone — no software on your device

The script and a mouse jiggler solve the same narrow problem — the inactivity timer, while your PC is on and unlocked — for free or close to it. Neither one touches the lock-screen case, because both depend on your device being awake to do anything at all. If you've read this far because a script felt like the "free" option, it's worth being clear-eyed that it's free and limited, not free and complete.

How Stay Green On Teams Is Different

Stay Green On Teams doesn't run anything on your machine, so none of the four breakages above apply. A cloud worker holds your Available status directly with Microsoft's Teams infrastructure using your own session credentials — the signal was never coming from your device, so locking it, closing it, or restarting it doesn't touch it. You set the hours you want to appear Available, and Teams shows you as Available for exactly those hours, whether your laptop is open or in a bag.

If the script's four breakages are dealbreakers — you're on a managed device, you actually lock your screen, or you want to close the laptop and leave — Stay Green On Teams is the version of this that has none of them. Start free → — 14-day trial, no card.

Skip the Script. Skip the Lock-Screen Gap.

Stay Green On Teams holds your Available status from the cloud on your schedule — no PowerShell window, no Scheduled Task, no gap the moment you lock your PC.

Start for free →

14-day free trial, no credit card required — cancel anytime.

FREQUENTLY ASKED
How do I keep my Teams status active with PowerShell?
Run a loop that sends a harmless keystroke — F15 is the standard choice because almost no keyboard has one, so it can't trigger a shortcut or type into a document — every couple of minutes using System.Windows.Forms.SendKeys. Teams reads that as real input and resets its ~5-minute inactivity timer. The script only works while you're logged in and unlocked; it does nothing once the screen locks.
Does a PowerShell script survive a locked screen?
No. Windows blocks synthetic input — including SendKeys — from reaching a locked session entirely, by design, for security reasons. The script keeps running in the background, but every keystroke it sends is silently dropped until you unlock. Teams will still flip you to Away the moment you lock your PC, script or no script.
Will IT or antivirus flag a keep-active script?
It can. A background PowerShell process sending synthetic keystrokes on an infinite loop matches a pattern some EDR and endpoint-monitoring tools watch for, since the same technique is used by actual input-simulation malware. On a personal machine it's rarely an issue; on a managed corporate device with Conditional Access or endpoint monitoring, it can trigger an alert or get killed by policy — check with IT before running it there.
Do I need admin rights to run it?
No. The script only sends a keystroke to the currently logged-in session, which doesn't require elevation. You will need to allow local script execution once, via Set-ExecutionPolicy -Scope CurrentUser RemoteSigned, if PowerShell's default policy is blocking .ps1 files from running.
What happens to the script when my laptop restarts?
It stops. A PowerShell window or background job doesn't survive a reboot on its own. Registering it as a Scheduled Task with an AtLogOn trigger makes it start automatically every time you sign back in, but you'll still need to be logged in and unlocked for it to do anything.
Is there a way to keep Teams green that doesn't break on lock or reboot?
Yes — a cloud-based presence service. Instead of simulating input on your device, it holds your Available status directly with Microsoft's Teams infrastructure from a server. Locking your screen, closing the lid, or restarting your laptop doesn't touch it, because the signal was never coming from your device in the first place.