spot_img

PowerShell Start-Process

The Start-Process cmdlet in PowerShell starts one or more processes on the local computer. The saps and start are the two aliases for this cmdlet.

Syntax

Parameters

We can use the following parameters of Start-Process cmdlet to specify the options, such as starting a process in new window, loading a user profile, or using the alternate credentials.

-FilePath

The -FilePath parameter is used to specify the filename of a program which runs in a process. Enter the name of document file or executable file, which is associated with the program on a computer.

-ArgumentList

The -ArgumentList parameter specifies the parameter and its values to use when the cmdlet begins the process.

-Credential

The -Credential parameter is used to give permissions to the user account to perform the process.

-WorkingDirectory

This parameter is used to specify the location of a file which executes in a process.

-LoadUserProfile

This parameter is used in this cmdlet to load the user profile of windows, which is stored in the HKEY_USERS registry key for the current user.

-NoNewWindow

This parameter starts the new process in the console of current window. By default, the PowerShell opens a new window for executing a new process.

-PassThru

This parameter returns the object for each process, which is started by the cmdlet.

-RedirectStandardError

This parameter sends the errors which are created by a process to the specified file. When using this cmdlet, you need to enter the path and name of the file. By default, the errors of a process are displayed on the console.

-RedirectStandardInput

When this parameter is used in the command, the processes can read the inputs from the specified file. To use this parameter, you need to enter the path and name of the file. By default, a process reads the inputs from the keyboard.

-RedirectStandardOutput

This parameter sends the output, which is created by a process to the specified file. When using this cmdlet, you need to enter the path and name of the file. By default, the output of a process is displayed on the console.

-WindowStyle

This parameter is used to specify the windows state, which is used for the new process. Following are the acceptable values for this parameter:

  • Hidden
  • Normal (Default value)
  • Maximized, and
  • Minimized

Note: We cannot use both the parameters NoNewWindow and WindowStyle in the same command.

-Wait

This parameter is used in this cmdlet to wait for a process to be completed before accepting any more inputs.

Examples

Example 1: open a file of notepad using a variable

PowerShell Start-Process

In this example, the first command uses a variable which stores the text file. The second command opens a text file by using the variable with Start-Process cmdlet.

Example 2: Start PowerShell as an administrator

PowerShell Start-Process

In this example, the command starts the PowerShell by using the “Run as Administrator” option.

Example 3: Start a process in a maximized window

PowerShell Start-Process

In this example, the command starts the notepad.exe process. The command maximizes the notepad window and retains the window until the process completes.


spot_img
Previous articleSSRS vs Power BI
Next articleExcel VBA Find