The Start-Process is a PowerShell command used to start single or more processes in a controlled and managed way. By default, the started process inherits all current PowerShell environment. The Start-Process can execute or start an executable file, batch script, MS-DOS and PowerShell command even Java application. The Start-Process can be used to specify user profile, windows status, and credentials, etc.
Start New Process or Run Executable
The most basic usage of the Start-Process command is providing the executable file, batch or script file, or command like below.
Alternatively the -FilePath attribute can be used to specify the file location we want to execute.
Start-Process -FilePath notepad.exe
The complete path of the executable file or batch file can be specified below. In the following example, we will execute a batch file which is located under the “D:\scripts” directory.
Start-Process -FilePath "D:\scripts\backup.bat"
Set Standard Input As File
A process input can be specified with the standard input where provided standard input content is redirected into the given process. The -RedirectStandardInput can be used to set a file as input into the newly created process.
Start-Process -FilePath "D:\scripts\backup.bat" -RedirectStandardInput test.txt
Set Standard Output As File
When a process executed it may create some output that can be printed to the terminal, screen, or file. We can use the -RedirectStandardOuput attribute in order to specify the output into a file.
Start-Process -FilePath "D:\scripts\backup.bat" -RedirectStandardOutput test.txt
Set Standard Error Output As File
While running a process errors may occur and information about these errors is printed into the console or terminal by default. By using the -RedirectStandardError attribute the output can be redirected into a file like below.
Start-Process -FilePath "D:\scripts\backup.bat" -RedirectStandardError errors.txt
Set Working Directory
By default new process is executed in the current working directory. A new working directory can be set by using the -WorkingDirectory attribute like below.
Start-Process notepad.exe -WorkingDirectory "D:\"
Create New Environment
By default, the Start-Process runs the given process with the current user environment. The current user environment variables and configuration is used. A new environment can be created with the -UseNewEnvironment like below.
Start-Process notepad.exe -UseNewEnvironment
Start Process As Maximized Window
The Start-Process command can start a command-line process or a GUI process which may have some GUI. The GUI window size can be set with the -WindowStyle attribute. This attribute can be set as Maximized to make the new process window maximized.
Start-Process notepad.exe -WindowStyle Maximized
Start Process As Different User
By default, the started process is executed as the current user privileges. But the process privileges can be changed with the -Credential attribute by providing the user we want to execute.
Start-Process notepad.exe -Verb runas
The user name can be change in the credential request too.
Start Process As Different Administrator
But using the -Verb runas which will ask for the user we want to run. This will ask you whether you want to run the given process as root. Simply accept this.
Start-Process notepad.exe -Verb runas
Start Process with Specified Arguments
Commands, processes, or batch files may accept single or multiple arguments in order to get some input data. This input data is called an argument and the Start-Process command can provide arguments to the started process with the -ArgumentList. Provided argument list passed into the processes as arguments.
Start-Process chrome.exe -ArgumentList "www.windowstect.com www.wisetut.com"