Start-Process

Start one or more processes.

Syntax
      Start-Process [-FilePath] string [[-ArgumentList] string[]]
         [-Credential PSCredential] [-LoadUserProfile]
            [-NoNewWindow] [-PassThru] [-RedirectStandardError string]
               [-RedirectStandardInput string] [-RedirectStandardOutput string]
                  [-UseNewEnvironment] [-Wait] [-WorkingDirectory string]
                     [CommonParameters]

      Start-Process [-FilePath] string [[-ArgumentList] string[]]
         [-PassThru] [-Verb string] [-Wait]
            [-WindowStyle  {Normal | Hidden | Minimized | Maximized}]
               [-WorkingDirectory string] [CommonParameters]

Key
   -ArgumentList string[]
       Specify parameters or parameter values to use when starting the process.
       The parameter name ("Arguments") is optional.

   -Credential PSCredential
       A user account that has permission to perform this action.
       Type a user-name, such as "User64" or "Domain64\User64", or enter a
       PSCredential object, such as one from the Get-Credential cmdlet.
       By default, the cmdlet uses the credentials of the current user.

   -FilePath string
       The path (optional) and file name of the program that runs in the
       process. Enter the name of an executable file or of a document,
       such as a .txt or .doc file, that is associated with a program.
       Required.

       If only a file name is given, use -WorkingDirectory to specify the path.

   -LoadUserProfile
       Load the Windows user profile stored in the HKEY_USERS registry key
       for the current user. The default value is FALSE.

       This parameter does not affect the PowerShell profiles. (See about_Profiles.)

   -NoNewWindow
       Prevent the process from running in a new window.
       By default, the process runs in a new window.

   -PassThru
       Return a process object for each process that the cmdlet started.
       By default, this cmdlet does not generate any output.

   -RedirectStandardError string
       Send any errors generated by the process to a file that you specify.
       Enter the path and file name. By default, the errors are displayed in the console.

   -RedirectStandardInput string
       Read input from the specified file.
       Enter the path and file name of the input file.
       By default, the process gets its input from the keyboard.

   -RedirectStandardOutput string
       Sends the output generated by the process to a file.
       Enter the path and file name. 
       By default, the output is displayed in the console.

   -UseNewEnvironment
       Use new environment variables specified for the process.
       By default, the started process runs with the environment variables
       specified for the computer and user.

   -Verb string
       A verb to be used when starting the process, such as Edit, Open, or Print.
       Each file type has a set of verbs that you can use.
       To find the verbs that can be used with the process, use the Verbs property of the object.

   -Wait
       Wait for the specified process to complete before accepting more input.
       This parameter suppresses the command  prompt or retains the window
       until the process completes.

   -WindowStyle ProcessWindowStyle
       The state of the windows used for the process.
       Valid values are Normal, Hidden, Minimized, and Maximized.

    -WorkingDirectory string
       The location of the executable file or document that runs
       in the process.  The default is the current directory.

   CommonParameters:
       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable,
       -OutBuffer -OutVariable.

Standard Aliases for Start-Process: saps, start

Examples

Start a process that uses Sort.exe in the current directory:

PS C:\> start-process sort.exe

Start a process that prints the C:\Demo\MyFile.txt file:

PS C:\> start-process myfile.txt -workingdirectory "C:\Demo" -verb Print

Start the Notepad process. Maximizes the window and wait until the process completes:

PS C:\> start-process notepad -wait -windowstyle Maximized

Start a process that sorts a file and returns the sorted items in Sorted.txt , write any errors to SortError.txt :

PS C:\> start-process Sort.exe -RedirectStandardInput C:\Demo\Testsort.txt -RedirectStandardOutput C:\Demo\Sorted.txt -RedirectStandardError C:\Demo\SortError.txt

Start a process using the WMI.Win32_Process class’s Create() function and return the Process ID, this PID can then be used later to alter or stop the process:

PS C:\> $pclass = [wmiclass]'root\cimv2:Win32_Process'
PS C:\> $new_pid = $pclass.Create('notepad.exe', '.', $null).ProcessId

Create function syntax: .Create(commandline, currentdirectory, parameters)

Start a process using the .NET System.Diagnostics.Process class’s start method and return the Process ID, this PID can then be used later to alter or stop the process:

PS C:\> $new_pid = [diagnostics.process]::start("notepad.exe")

“Somebody should tell us, right at the start of our lives, that we are dying. Then we might live life to the limit, every minute of every day. Do it! I say. Whatever you want to do, do it now! There are only so many tomorrows” - Pope Paul VI

Related:

Get-Process - Get a list of processes on a machine
Stop-Process - Stop a running process (Kill)


© Copyright SS64.com 1999-2013
Some rights reserved