PowerShell -NoNewWindow Parameter
last modified February 15, 2025
This tutorial covers the PowerShell -NoNewWindow
parameter.
It explains how to run processes in the current console window. The
parameter is used with several process-related cmdlets. Examples show
practical applications of this parameter.
Understanding -NoNewWindow
The -NoNewWindow
parameter prevents PowerShell from opening
a new window when starting a process. By default, some cmdlets launch
processes in new windows. This parameter keeps the process output in the
current console. It's useful for scripting and output capture.
Basic usage with Start-Process
The most common use of -NoNewWindow
is with Start-Process.
Without it, Start-Process opens a new window for the application. With
it, the process runs in the current console window. This example starts
Notepad in the current window.
Start-Process notepad -NoNewWindow
This command launches Notepad without creating a new window. The output appears in the current PowerShell console. Note that GUI apps like Notepad may still create their own windows.
Running command-line tools
Command-line tools work particularly well with -NoNewWindow
.
Their output appears directly in the PowerShell console. This example runs
the ipconfig command. The network configuration output appears immediately.
Start-Process ipconfig -NoNewWindow -Wait
The -Wait
parameter ensures PowerShell waits for completion.
Without it, the command would run asynchronously. The output appears in
the current console window.
Capturing output with -NoNewWindow
Combining -NoNewWindow
with redirection captures output.
This example runs ping and saves results to a file. The command runs in
the current console but output goes to the file.
Start-Process ping -ArgumentList "google.com" -NoNewWindow -Wait -RedirectStandardOutput ping_results.txt
The ping command output is saved to ping_results.txt. Without
-NoNewWindow
, this would create a separate window. The
-RedirectStandardOutput
parameter handles the file output.
Running PowerShell scripts
You can use -NoNewWindow
to run PowerShell scripts. This
keeps all output in the current console session. The example runs another
script without spawning a new window. This maintains a cleaner workspace.
Start-Process powershell -ArgumentList "-File C:\scripts\test.ps1" -NoNewWindow -Wait
The script test.ps1 runs in the current console window. All its output
appears in the same window as the parent script. The -Wait
ensures sequential execution.
Combining with -PassThru
The -PassThru
parameter returns process objects. Combined
with -NoNewWindow
, it allows process management. This
example starts a process and stores its object. The object can then be
used to monitor or stop the process.
$process = Start-Process notepad -NoNewWindow -PassThru $process | Get-Process
The process object is stored in $process. The second line displays information about it. This technique works well for process automation scripts.
Running hidden processes
-NoNewWindow
can be combined with -WindowStyle Hidden
.
This runs processes without any visible window. The example starts a
background PowerShell command. The command executes without any UI.
Start-Process powershell -ArgumentList "-Command Get-Date" -NoNewWindow -WindowStyle Hidden
The Get-Date command runs completely hidden. No console window appears during execution. This is useful for background tasks and scheduled jobs.
Using with Invoke-Command
-NoNewWindow
also works with Invoke-Command for remote
sessions. This keeps remote command output in the local console. The
example runs a command on a remote computer. Results appear in the
current window.
Invoke-Command -ComputerName Server01 -ScriptBlock { Get-Process } -NoNewWindow
The remote Get-Process output appears locally. Without
-NoNewWindow
, this might open separate windows. The
parameter ensures a cleaner remote management experience.
Error handling with -NoNewWindow
Error streams can be captured when using -NoNewWindow
. This
example demonstrates error redirection. The command attempts to access a
non-existent file. Errors are redirected to a log file.
Start-Process powershell -ArgumentList "-Command Get-Content nofile.txt" -NoNewWindow -Wait -RedirectStandardError errors.log
Error messages are saved to errors.log. The console shows no error output. This technique is useful for logging and debugging scripts.
Source
This tutorial has covered the PowerShell -NoNewWindow
parameter.
The examples demonstrated various practical applications. This parameter is
valuable for console-based process management.
Author
List all PowerShell tutorials.