HOWTO · PowerShell
How to Run a PowerShell Script Without Displaying a Window
Run PowerShell scripts with a hidden window or Task Scheduler, and understand launch-context limits, batch files, and service alternatives.
On this page
On Windows, launch a script with powershell.exe -NoProfile -WindowStyle Hidden -File "C:\Scripts\Task.ps1", replacing the quoted path with your script’s absolute path. The -WindowStyle Hidden parameter controls the PowerShell window’s appearance; it does not guarantee that every launcher or child application stays invisible.
Run PowerShell with -WindowStyle Hidden
Use the command above from a Windows launcher such as the Run dialog. -File identifies the script; quotes protect paths containing spaces. -NoProfile skips profile startup scripts, so your task must load its own dependencies.
Window visibility depends on the host and launch context: a console can appear briefly during startup. Do not rely on this command to hide an already-open terminal. Applications started by the script can display their own windows. A hidden window also does not hide the process from Task Manager.
The Windows launch instructions in this article are unexecuted illustrations; no observed window behavior or command output is supplied.
Launch the Script from a Batch File
Save two lines in run_script.bat: first @echo off, then powershell.exe -NoProfile -WindowStyle Hidden -File "C:\Scripts\Task.ps1". Replace the path before running it.
@echo off suppresses command echo in the batch console. It does not hide that console, suppress the script’s output, or prevent a startup flash. A batch file is convenient for repeated launches, but Task Scheduler is a better fit for unattended work without an interactive console.
Run the Script with Task Scheduler
- Open Task Scheduler, choose Create Task, and give the task a descriptive name.
- On General, select an account with access to the script and its resources. For unattended work, choose Run whether user is logged on or not and supply credentials if prompted. This uses a noninteractive context; scripts requiring desktop interaction may fail. Enable Run with highest privileges only when the task requires elevation and the account is authorized for it. Elevation does not control visibility.
- On Triggers, add the schedule or event you need.
- On Actions, choose New and Start a program. Select the installed
powershell.exeexecutable. In Add arguments, enter-NoProfile -NonInteractive -WindowStyle Hidden -File "C:\Scripts\Task.ps1". Set Start in toC:\Scriptswithout quotes, adapting both paths.-NonInteractiveprevents input prompts from waiting for a user; it does not hide windows. - Save the task, right-click it, and choose Run for a manual test. This starts it immediately without waiting for its trigger. Inspect its history, Last Run Result, and the script’s logs.
Use PSExec or NSSM Only for Suitable Tasks
PSExec, from Microsoft Sysinternals, suits remote administration or execution under another account. Its -d option means do not wait, and -s selects the SYSTEM account; neither is a window-hiding switch. SYSTEM has different resource access from your user account. These options are unnecessary for ordinary hidden launches.
NSSM (Non-Sucking Service Manager) wraps applications as Windows services. Obtain it from its official download site, https://nssm.cc/download. Service installation requires administrative rights. Configure the PowerShell executable, script arguments, working directory, service account, logging, and restart behavior deliberately. Use it for service-like workloads that need no interactive desktop; a short scheduled script usually needs only Task Scheduler. Execution-policy bypass changes script-policy handling, not window visibility, and is not required for hiding a window.
Test the Script and Choose the Right Method
First run your script visibly under the intended account. Check file permissions, dependencies, absolute paths, and execution-policy messages. Scheduled accounts may lack your mapped drives or profile settings. Save output and errors to a location that account can write; a disappearing window is no proof of success.
This self-contained PowerShell logging example is unexecuted. It writes a completion message to a temporary file, reads it, and removes the file afterward:
$logPath = [System.IO.Path]::GetTempFileName()
try {
'Task completed' | Set-Content -LiteralPath $logPath
Get-Content -LiteralPath $logPath
}
finally {
Remove-Item -LiteralPath $logPath
}
For your actual script, retain a stable log file and record failures as well as completion. Choose direct launch for occasional use, a batch file for convenience, Task Scheduler for unattended triggers, or NSSM for a service workload. Check desktop-dependent behavior on the target Windows machine before relying on any hidden launch.