It is one of the things I hear my colleagues, and even my girlfriend, mention regularly… Why does Microsoft Teams think I’m away while I’m not / My PC isn’t locked yet… I read a few solutions, setting your status duration to a date in the future, etc… Didn’t work 🙁 What does work is running my simple PowerShell scripts, which I will show you in this blog post 🙂
Disclaimer
This PowerShell script is a straightforward way to keep your Microsoft Teams status set to Available while watching work-related content on your machine (Training, internal video from work, etc. ), getting some coffee when working at home, or whatever action keeps you from moving your mouse or typing. I didn’t create this to make your boss think you’re working hard at home while you are watching NetFlix series 😀 It’s just something I found funny to write, not a serious project… (Busy week)
How does the script work?
You run the script, which will remain active until you press CTRL-C or close the PowerShell window. It checks if Microsoft Teams is running (The new version, of course) and will press the Num-Lock key twice (To toggle it back to on or off, leaving it like you have it configured). It will wait 60 seconds, press Num-Lock again, wait for 60 seconds, and so on. If Microsoft Teams is not running at that moment, or if you close it for an update, it will wait 15 seconds to see if it’s running again and continue the 60-second Num-Lock loop.
If you want to change the keys being pressed to something else, use this table to use other characters. Using Num-Lock seems to work fine, but it could trigger something while watching media (NetFlix will show the title of the item you’re watching, for example).
You can also change the frequency of 60 seconds to any value you like, but to keep Microsoft Teams awake, it must be below 300 seconds because Teams will think you’re away after 5 minutes. (Change the Write-Hosts prompt too 🙂 )
Running the script
You can save the script’s contents to, for example, c:\scripts\Stop-MicrosoftTeamsAway.ps1 and run it in your PowerShell session. The output will look like this when Microsoft Teams is Active:

When Teams is not running, it will look like this and return to the output as shown above when Teams is active again:

Wrapping up
This is how you keep Microsoft Teams in an Available status 🙂 Run it from your PowerShell prompt when needed, or schedule it on your system using Scheduled Tasks. (Configure it to run as your user to make it work. Admin rights are needed, or at least the “Log on as a batch-job” permission.)
The script
Save the script’s contents below to, for example, c:\scripts\Stop-MicrosoftTeamsAway.ps1.
while ($true) {
try {
Get-Process -Name 'ms-teams' -ErrorAction stop | Out-Null
Write-Host ("{0} - Microsoft Teams is running..." -f $(get-date)) -ForegroundColor Green
$wshell = New-Object -ComObject wscript.shell
$wshell.sendkeys("{NUMLOCK}{NUMLOCK}")
Write-Host ("{0} - Pressed NUMLOCK twice and waiting for 60 seconds" -f $(get-date)) -ForegroundColor Green
Start-Sleep -Seconds 60
}
catch {
Write-Warning ("{0} - Microsoft Teams is not running, sleeping for 15 seconds..." -f $(get-date))
Start-Sleep -Seconds 15
}
}
Download the script(s) from GitHub here.
Thank you so much!
I used this and scheduled it with task scheduler. So nice, thanks again!
Thank you 😊
Your solution is so simple and genial. 🙂 I love it.
Thank you!
Thanks for this. It doesn’t seem to be working properly for me, though. I am running version 25241.203.3947.4411 … when Teams actually is running, I get both of the above status messages every 15 seconds. And status changes to Away in the typical time frame.
You’re running this in a non-admin command prompt? I mean, the script runs in the same user space as Teams?
Yes that is right.
Perhaps I misunderstood you when you wrote above that ‘Admin rights are needed, or at least the “Log on as a batch-job” permissions’; I thought you meant that those rights are necessary in order to schedule the script, not to run it at all.
I’m not an administrator on this computer. So I guess I don’t have any options for keeping the status as Available? Thanks.
I don’t nderstand you perhaps, but you can run the script in a PowerShell prompt as a normal user? (Not as Administrator) If so, it should work because my girlfriend even still uses it regurarly… You should run it as the same user you start Teams with