You are currently viewing How to Keep Teams Status Active: PowerShell

How to Keep Teams Status Active: PowerShell

Hello, everyone. We’ll discuss how to keep Teams status active even if you are away from the system for a long time. 

As you know, if you set the MS Team status to available or busy and when you are away from the system or stop using the mouse and keyboard, the automatically available status icon gets changed to away.

How It Works:

Before implementing the solution, we must first understand how it works. So when you keep moving the mouse cursor or pressing any key from the keyboard ten system or this Teams application, receive a signal that you are still using the system and your session is active.

How to Keep Teams Status Active-1: PowerShell Configuration

We will implement the PowerShell-based solution to keep the status always available. Search for PowerShell and open the Windows PowerShell ISE.  

This is a .Net command which PowerShell can execute. So this command will press a key like physically when you press any button on the keyboard.

 how to keep Teams status active even if you are away from the system for a long time.
.Net command to How to Keep Teams Status Active
#Press a key
[Windows.Forms.Sendkeys]::SendWait("")

There is a syntax format for using that keys. Click here to find the code for the particular keys. You will find almost all key codes except alphabets and numbers.

SendKeys Class Code Table

Now be careful while picking the key, that we need to use in the script because if you use something like ENTER key while working on any other application, it can also create a problem because it will automatically press the enter key in other applications, which can generate unexpected results.

In my thinking, it’s safe to use the SCROLL LOCK key. But if you find any other keys useful, you can use that.

Apply While loop:

Now we have to run this in a loop to continue working. Let’s put this command in a while loop. You can copy and paste if you don’t understand the PowerShell loop concept. then make the condition to $true. It’s always getting a true result; based on that, it’ll keep executing inside commands every time and pressing the scroll lock key.

While ($true) {

 #Keep Pressing Scrolllock key
 [Windows.Forms.Sendkeys]::SendWait("{SCROLLLOCK}")

 }

Apply Delay:

Now the second part. You don’t need to run it every second so put an interval here also by using the sleep command. You need to observe on your system how long it takes for Team status to get changed in the case of inactivity. If your team status changes every 5 minutes in case of inactivity, you may convert the 5 minutes into seconds. That should be around 300 seconds.

#Wait for 5 minutes
Sleep -Seconds 300

Now you can execute this command with an interval of 5 minutes. After executing the script, the sleep line is waiting for 5 minutes then again, it’s going in the loop for the next execution. So this can work like this.

Load Class Library:

Now I have faced one more problem while executing from this PowerShell ISE, it worked, but while executing from the PowerShell.exe, it’s giving an error because of missing library classes in the session. We must define the following required library to load classes to run the Sendkeys successfully.

#Load library
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

Now click on the save button to Save this script, select the location where you want to save it, and give a name. Next time you start the system, you need to go to that location wherever you have saved the script and run it with PowerShell. It’s running in the loop and will not give any result o the screen but it’s running.

how to keep Teams status active even if you are away from the system for a long time.
How to Keep Teams Status Active 1: PowerShell Configuration

Now another problem: while working on any other application, it shows that you are running a PowerShell script. It would be best if you hid this and want to run it automatically. You don’t need to go every time to the particular location and run manually. This should get executed automatically on every login. For that configuration, we will use a task scheduler to execute the cmd batch script, which will run the PowerShell script in hidden mode.

How to Keep Teams Status Active-2: Batch File Configuration

I will create a batch file first here, right-click –> new, and then create a text file. You should not display any information on the screen. For that, we will use the following commands.

How to Keep Teams Status Active 2: Batch File Configuration
How to Keep Teams Status Active 2: Batch File Configuration

We are setting the window style to hidden so that when the PowerShell script gets executed, it’ll not keep showing on the screen. Now save it and change the file extension from text to CMD.

@Echo off

cmd /c powerShell.exe -ExecutionPolicy Bypass -Windowstyle hidden -file "C:\path of script file\KeepTeamsStatusActive.ps1"

Enable to Show File Extension Types:

If in your system the extension is not showing then simply go to the tab View >> Options >> Change folder and search options.

Click on the View tab in the open window then there could be a checkmark on hide extensions for known file types.

Now uncheck it and then click on the OK button then it will start showing the extension also so that you can change it. 

Enable to Show File Extension Types:
Enable to Show File Extension Types:

You may also watch this video-based tutorial solution to configure how to keep Teams status active.

PowerShell: How to Keep Teams Status Active When Away from Computer

How to Keep Teams Status Active-3: Task Scheduler Configuration

Overview: The Task Scheduler is a built-in utility in Windows that allows you to schedule tasks to run automatically at a specified time or in response to a trigger. Some benefits of using the Task Scheduler include the following:

  • Automation: The Task Scheduler can automate tasks, freeing you up to do other work.
  • Improved efficiency: The Task Scheduler can help you work more efficiently by automating tasks.
  • Enhanced security: The Task Scheduler can run tasks with elevated privileges, allowing you to perform administrative tasks without having to log in to the system with an administrator account.
  • Customization: The Task Scheduler allows you to customize the scheduling of tasks to meet your specific needs.
How to Keep Teams Status Active 3: Task Scheduler Configuration
Create a Task in Task Scheduler

Steps to configure: Now open the task scheduler by searching in the Start menu search box.

  • In the Task Scheduler window, click on the “Create Task” link in the Actions pane on the right-hand side.
  • Type a name and description for the task.
  • Select the trigger for the task. For example, you can run the task “At log on“.
  • Select the action for the task. you can choose to “start a program”.
  • Type the file name of the cmd file that you want to run and any arguments.
  • Review the settings and click Finish to create the task.
  • You can now modify, enable or disable the task by going to the task list, right-clicking on the task, and choosing the option you want.
How to Keep Teams Status Active 3: Task Scheduler Configuration
How to Keep Teams Status Active 3: Task Scheduler Configuration
How to Keep Teams Status Active 3: Task Scheduler Configuration
Here we need to mention the batch file name and enter the complete path of the file in Start in box.

Now, whenever you log in to the system automatically it will start running in the background.

But if you want to kill that temporarily you can stop the PowerShell process from the task manager and for parament removal, you can disable or delete it from the task Scheduler where we’ve configured it.

This way you can keep the Microsoft Teams status active when away from the system for a long time. So this method is just for testing purposes and we do not encourage you to any misuse it. So keep working and be productive.

Summary:

In this article, we learned how we can press a key virtually through PowerShell and configure it to execute automatically through Task Scheduler. This way Windows OS and other applications like Teams status get always an active signal and keep showing active status. This method is the solution to your question “how to keep Teams status active”.

Please check this page for more learning resources.

Please also take the following course for more learning….

Advance IT Troubleshooting for Desktop Support Professional
Advance IT Troubleshooting for Desktop Support Professional

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.