Back to Blog
Guide

PowerShell Script to Keep Teams Active: F15, Num Lock and a Work-Hours Timer

A PowerShell script that presses F15 once a minute keeps Microsoft Teams Available, because Teams goes Away only after about 5 minutes with no input anywhere on the PC. Copy-ready scripts for PowerShell (F15, Num Lock, stop at a set time), Python and Mac, why SetThreadExecutionState does not work for Teams, and what the script cannot hide.

Slack Green Team
September 25, 2026
October 7, 2026
5 min read
Share:
microsoft teams
powershell
presence status
windows

A PowerShell script that presses F15 once a minute keeps Microsoft Teams Available. Teams switches you to Away after about 5 minutes with no keyboard or mouse input anywhere on the computer. F15 is a key no keyboard has, but Windows counts it as input, so the idle timer never reaches 5 minutes. The script needs no admin rights. Here it is, with a stop time so it ends with your work day:

# keep-teams-active.ps1 - presses F15 every 60 seconds until 17:30, Ctrl+C to stop
$shell = New-Object -ComObject WScript.Shell
$end = Get-Date '17:30'
while ((Get-Date) -lt $end) {
    $shell.SendKeys('{F15}')
    Start-Sleep -Seconds 60
}

A script that only blocks sleep, such as one calling SetThreadExecutionState, does not keep Teams green: it sends no input. Scripts that press a key or move the mouse help the Slack desktop app too, which counts input anywhere on the computer, while the PC is unlocked. Many people use both apps; see keep Teams and Slack active at the same time.

PowerShell script to keep Teams active: F15 every 60 seconds, no admin rights, stops at the end of the day

Why an F15 script keeps Teams Available

Why an F15 press keeps Teams Available: input resets the Windows idle timer that Teams reads

Microsoft Learn, in User presence in Teams, says your presence becomes Away "if they're inactive for a few minutes or if the computer is locked", and Offline when the computer sleeps. Teams judges "inactive" from the computer's idle time, not from activity in the Teams window. Typing in Excel keeps you green. So does a scripted keypress. The timings are in how long before Teams shows you as Away.

Two things a script cannot beat:

  • • Locking the PC switches Teams to Away at once, script or not. If your screen locks after 5 idle minutes by policy, the keypresses also stop that lock, because they are input.
  • • Sleep switches Teams to Offline. Input keeps a PC from idle sleep, but closing the lid still sleeps it.
  • The PowerShell scripts

    Plain F15 loop

    The shortest version. It runs until you press Ctrl+C:

    # f15.ps1 - presses F15 once a minute until you press Ctrl+C
    $shell = New-Object -ComObject WScript.Shell
    while ($true) {
        $shell.SendKeys('{F15}')
        Start-Sleep -Seconds 60
    }

    This is the same loop as script 2 in keep a Windows PC awake with PowerShell. SendKeys sends the key to whatever window has focus. Most apps ignore F15, which is why it is the usual choice.

    Num Lock version

    Some scripts on Reddit and GitHub press Num Lock twice instead, so the key state ends where it started:

    # numlock.ps1 - toggles Num Lock off and on every 60 seconds
    $shell = New-Object -ComObject WScript.Shell
    while ($true) {
        $shell.SendKeys('{NUMLOCK}')
        Start-Sleep -Milliseconds 200
        $shell.SendKeys('{NUMLOCK}')
        Start-Sleep -Seconds 60
    }

    It works the same way for Teams. The Num Lock light on your keyboard flickers each minute, and if the script is stopped between the two presses, Num Lock stays off. F15 has neither problem. The same F15 trick on a Mac or Linux machine is in keyboard jiggler.

    Work-hours version

    The script at the top of this page stops at 17:30. To start later in the day and stop at a set time, check the clock on every loop:

    # keep-teams-active-hours.ps1 - presses F15 every 60 s between 09:00 and 17:30
    $shell = New-Object -ComObject WScript.Shell
    $start = [TimeSpan]'09:00'
    $stop  = [TimeSpan]'17:30'
    while ((Get-Date).TimeOfDay -lt $stop) {
        if ((Get-Date).TimeOfDay -ge $start) { $shell.SendKeys('{F15}') }
        Start-Sleep -Seconds 60
    }

    Change the two times to your own hours. After 17:30 the script ends by itself, and Teams goes Away about 5 minutes later.

    How to run a PowerShell script to keep Teams active

    How to run the script: save, open PowerShell, run with Bypass, stop with Ctrl+C

  • Paste the script into Notepad and save it as keep-teams-active.ps1.
  • Open PowerShell. No admin rights are needed. Go to the folder with cd.
  • Run it:
  • powershell -ExecutionPolicy Bypass -File .\keep-teams-active.ps1

  • Leave the window open, minimized if you like. Press Ctrl+C or close the window to stop it.

-ExecutionPolicy Bypass applies to this one run only and does not change a system setting. If your company blocks PowerShell through Group Policy or AppLocker, the script will not start, and you should not work around that. The settings-only options are in keep a work computer awake without admin rights.

Python and Mac scripts to keep Teams active

Which script keeps Teams Available: F15, Num Lock, SetThreadExecutionState, powercfg, Python, Mac cliclick

Python, on Windows or Mac. pyautogui can move the pointer one pixel and back once a minute:

# keep_teams_active.py - pip install pyautogui, then: python keep_teams_active.py
import time
import pyautogui

while True:
    pyautogui.moveRel(1, 0)
    pyautogui.moveRel(-1, 0)
    time.sleep(60)

Moving the pointer to a screen corner stops it (a pyautogui safety rule), and so does Ctrl+C. On a Mac, allow Terminal in System Settings, Privacy & Security, Accessibility first. Avoid pressing F15 on a Mac: on some Apple keyboards F14 and F15 change the screen brightness.

Mac, no Python. cliclick from Homebrew does the same from Terminal:

brew install cliclick
while true; do cliclick m:+1,+0 m:-1,+0; sleep 60; done

To also stop the Mac from sleeping, wrap it in caffeinate, which ships with macOS. More Mac options, including free jiggler apps, are in mouse jiggler for Mac. A Mac script that stops by itself after 8 hours is in how to keep Teams active on a Mac.

ScriptKeeps Teams greenKeeps PC awake
PowerShell F15YesYes
PowerShell Num Lock twiceYesYes
PowerShell SetThreadExecutionStateNoYes
powercfg timeouts set to 0NoYes, while plugged in
Python pyautogui nudgeYesYes
Mac cliclick loopYesWith caffeinate

Can your employer see a keep-Teams-active script?

Teams itself shows only the status: Available, not "Available because of a script". But the input is not invisible. Windows flags keys sent by SendKeys as injected input, and endpoint monitoring software can log that, along with the PowerShell process and its command line. A script that presses F15 at exactly 60-second intervals for eight hours is also an easy pattern to spot in activity data. What Teams reports to admins is in does Microsoft Teams track your activity, and detection of jigglers in general is in can a mouse jiggler be detected.

Teams has no setting that holds you at Available. The status Duration option works for Busy, Do not disturb and the others, but not for Available, so idle time still decides. The options that do not need a script are in how to keep your Teams status available.

Quick answers

Does it work in the new Teams app? Yes. New Teams reads the computer's idle time the same way.

Will the script keep my Teams mobile status green? No. The phone's Teams status depends on the app being on screen; see does Teams stay green on mobile.

Why does Teams still show Away with the script running? The PC locked, the lid closed, or the script window closed. Check that PowerShell is still running, and that nothing locks the screen by policy.

Related Articles

Guide

How to Delete Someone Else's Message in Slack, Tested as Workspace Owner

As the owner of a free-plan workspace we deleted an app's message, a webhook message and two system messages, in Slack web and with the API, and checked which settings exist.

Slack Green Team
Guide

Slack Drafts: Where to Find Them, and What Happens When You Schedule, Archive or Leave

We wrote drafts in a channel, a thread and a DM in Slack web, then scheduled, sent, archived and left, and checked Drafts & sent and Slack's API after each step.

Slack Green Team
Guide

Slack Mark as Unread: Option-Click, the Menu, and What Clears It

We marked messages unread in a channel, a DM and a thread in Slack web, read the read state back from the API, and timed what clears it.

Slack Green Team