How to execute a powershell script without stealing focus? How to execute a powershell script without stealing focus? powershell powershell

How to execute a powershell script without stealing focus?


I know this question is old, but I've spent quite some time trying to figure out how to not lose focus from the current window for myself and found some information, so hopefully this will help future readers.

The easiest solution is just to literally simulate an Alt+Tab keypress from within your Powershell script instead of having to do it yourself. The following code comes from this StackOverflow answer:

[void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')[System.Windows.Forms.SendKeys]::SendWait("%{TAB}")# Retrieve the window handles...

...where % represents the Alt modifier and {TAB} is interpreted as the tab key.


  1. Create task that can be run on demand in Task Scheduler and executes your powershell script
  2. Make sure it is set to be run whether user is logged on or not
  3. Create a shortcut that starts the task

That allows your script to be run without visible window