Run a PowerShell Script Without Displaying a Window

PowerShell by Microsoft is a tool that comes in default with Windows operating systems, enabling Windows users with the automation functions based on command-line interfaces and commands.
PowerShell is a scripting tool and an automation tool; hence sometimes requires the application to run in the background quietly. Through this article, we will see how to run the PowerShell application silently in the background, executing commands in the background.
There are third-party tools that you can incorporate with PowerShell tools to achieve the hidden functionality of PowerShell. Although, there are easy ways to do this with PowerShell only.
Use hidden
as Window Style to Hide the PowerShell Window
One simple way to do the script window hiding would be by using the hidden
type as a window style. A window-style PowerShell Window would be shown briefly at the beginning and then hidden during the script execution.
The code we are talking about is as follows.
PowerShell.exe -windowstyle hidden { Script you want to execute.. }
PowerShell execution of the above command is shown in the below image.
Once entered, the window disappears, yet the application would be running in the background. As shown in the below image of background processes, PowerShell runs as a background process.
In this method, the user would initially see the PowerShell. So it is not truly hidden from the end-users. Even if the task is scheduled previously, the window would pop up and get hidden quickly.
However, there are other simple methods to achieve the true hidden functionality of PowerShell.
Use Task Scheduler to Hide PowerShell
With Task Scheduler of Windows, you can schedule a PowerShell script to run in tasks. There, you have to go to Tasks
and click Run whether user is logged on or not
, which would not show the window to the user at all.
The option is shown below, where you have to select the second radio button once the task is scheduled.
However, this method would affect the functionality of some scripts you try to use. Hence, you can also use third-party tools or community extensions for PowerShell.
Nimesha is a Full-stack Software Engineer for more than five years, he loves technology, as technology has the power to solve our many problems within just a minute. He have been contributing to various projects over the last 5+ years and working with almost all the so-called 03 tiers(DB, M-Tier, and Client). Recently, he has started working with DevOps technologies such as Azure administration, Kubernetes, Terraform automation, and Bash scripting as well.