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:
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.
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.
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.
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:
| Method | Cost | Survives lock screen? | Survives reboot? | IT/AV risk |
|---|---|---|---|---|
| PowerShell script (this page) | Free | No | Only with a Scheduled Task, and still needs unlock | Possible on managed devices |
| Hardware mouse jiggler | $15–30 | No | Yes (plug-and-play) | Low |
| Cloud presence service | Paid subscription | Yes | Yes | None — 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.