Table of Contents
Stop Teams from Changing from Available to Away Status
One issue that frequently comes up among my colleagues is the Microsoft Teams status showing ‘Away’ when I’m not, or my PC isn’t locked yet. I’ve tried several solutions, such as setting the status duration to a future date, but to no avail. However, I have found success with a simple PowerShell script, which I’ll share in this blog post.
The PowerShell script provides a simple method to maintain your Microsoft Teams status as ‘Available’ while you view work-related materials on your computer, such as training or internal work videos, getting some coffee when working at home, or whatever action keeps you from moving your mouse or typing.
The script
Save the script’s contents below to, for example, D:\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
}
}
How does the script work?
The script will continue to run 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 in some specific cases.
Running the script
You can save the script’s contents to, for example, D:\scripts\Stop-MicrosoftTeamsAway.ps1 and run it in your PowerShell session. The output will look like this when Microsoft Teams is Active:
. D:\scripts\Stop-MicrosoftTeamsAway.ps1
When Microsoft Teams is not running, it will look like the below screenshots and return to the output as shown above when Teams is active again:
Conclusion
To maintain an ‘Available’ status on Microsoft Teams, execute the script from your PowerShell prompt as required, or set it up in your system’s Scheduled Tasks. Ensure its configured to run under your user account for functionality. Administrative privileges, or at minimum the Log on as a batch-job permission, are necessary.
Not a reader? Watch this related video tutorial: