Start-Process (Microsoft.PowerShell.Management) - PowerShell (2023)

  • Reference
Module:
Microsoft.PowerShell.Management

Starts one or more processes on the local computer.

Syntax

Start-Process [-FilePath] <String> [[-ArgumentList] <String[]>] [-Credential <PSCredential>] [-WorkingDirectory <String>] [-LoadUserProfile] [-NoNewWindow] [-PassThru] [-RedirectStandardError <String>] [-RedirectStandardInput <String>] [-RedirectStandardOutput <String>] [-WindowStyle <ProcessWindowStyle>] [-Wait] [-UseNewEnvironment] [-WhatIf] [-Confirm] [<CommonParameters>]
Start-Process [-FilePath] <String> [[-ArgumentList] <String[]>] [-WorkingDirectory <String>] [-PassThru] [-Verb <String>] [-WindowStyle <ProcessWindowStyle>] [-Wait] [-WhatIf] [-Confirm] [<CommonParameters>]

Description

The Start-Process cmdlet starts one or more processes on the local computer. By default,Start-Process creates a new process that inherits all the environment variables that are definedin the current process.

To specify the program that runs in the process, enter an executable file or script file, or a filethat can be opened using a program on the computer. If you specify a non-executable file,Start-Process starts the program that's associated with the file, similar to the Invoke-Itemcmdlet.

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

Examples

Example 1: Start a process that uses default values

This example starts a process that uses the Sort.exe file in the current folder. The command usesall the default values, including the default window style, working folder, and credentials.

Start-Process -FilePath "sort.exe"

Example 2: Print a text file

This example starts a process that prints the C:\PS-Test\MyFile.txt file.

Start-Process -FilePath "myfile.txt" -WorkingDirectory "C:\PS-Test" -Verb Print

Example 3: Start a process to sort items to a new file

This example starts a process that sorts items in the TestSort.txt file and returns the sorteditems in the Sorted.txt files. Any errors are written to the SortError.txt file. TheUseNewEnvironment parameter specifies that the process runs with its own environment variables.

$processOptions = @{ FilePath = "sort.exe" RedirectStandardInput = "TestSort.txt" RedirectStandardOutput = "Sorted.txt" RedirectStandardError = "SortError.txt" UseNewEnvironment = $true}Start-Process @processOptions

This example uses splatting to pass parameters to the cmdlet. For more information, seeabout_Splatting.

Example 4: Start a process in a maximized window

This example starts the Notepad.exe process. It maximizes the window and retains the window untilthe process completes.

Start-Process -FilePath "notepad" -Wait -WindowStyle Maximized

Example 5: Start PowerShell as an administrator

This example starts PowerShell using the Run as administrator option.

Start-Process -FilePath "powershell" -Verb RunAs

Example 6: Using different verbs to start a process

This example shows how to find the verbs that can be used when starting a process. The availableverbs are determined by the filename extension of the file that runs in the process.

$startExe = New-Object System.Diagnostics.ProcessStartInfo -Args powershell.exe$startExe.verbsopenrunasrunasuser

The example uses New-Object to create a System.Diagnostics.ProcessStartInfo object forpowershell.exe, the file that runs in the PowerShell process. The Verbs property of theProcessStartInfo object shows that you can use the Open and RunAs verbs withpowershell.exe, or with any process that runs a .exe file.

Example 7: Specifying arguments to the process

Both commands start the Windows command interpreter, issuing a dir command on the Program Filesfolder. Because this foldername contains a space, the value needs surrounded with escaped quotes.Note that the first command specifies a string as ArgumentList. The second command is a stringarray.

Start-Process -FilePath "$env:comspec" -ArgumentList "/c dir `"%SystemDrive%\Program Files`""Start-Process -FilePath "$env:comspec" -ArgumentList "/c","dir","`"%SystemDrive%\Program Files`""

Example 8: Run a command as an Administrator using alternate credentials

On Windows, you can run Start-Process -Verb RunAs to start a process with elevated permissions.This elevates the current user's context. The Credential parameter allows you to specify analternate username and password, allowing you to start a process in a different user content.However, the Credential and Verb parameters can't be used together.

(Video) Using Start-Process to Start an Admin Powershell Instance - Quick Tip

To start a process with elevated rights, using alternate credentials, you must first startPowerShell using the alternate credentials, then use Start-Process to start the process withelevated rights.

$cred = Get-Credential$args = '-noprofile -command "Start-Process cmd.exe -Verb RunAs -args /k"'Start-Process pwsh.exe -Credential $cred -WindowStyle Hidden -ArgumentList $args

The example starts cmd.exe with elevated permissions from a PowerShell session that is runningunder alternate credentials.

Example 9: Create a detached process on Linux

On Windows, Start-Process creates an independent process that remains running independently of thelaunching shell. On non-Windows platforms, the newly started process is attached to the shell thatlaunched. If the launching shell is closed, the child process is terminated.

To avoid terminating the child process on Unix-like platforms, you can combine Start-Process withnohup. The following example launches a background instance of PowerShell on Linux that staysalive even after you close the launching session. The nohup command collects output in filenohup.out in the current directory.

# Runs for 2 minutes and appends output to ./nohup.outStart-Process nohup 'pwsh -noprofile -c "1..120 | % { Write-Host . -NoNewline; sleep 1 }"'

In this example, Start-Process is running the Linux nohup command, which launches pwsh as adetached process. For more information, see the nohup article onWikipedia.

Parameters

-ArgumentList

Specifies parameters or parameter values to use when this cmdlet starts the process. Arguments canbe accepted as a single string with the arguments separated by spaces, or as an array of stringsseparated by commas. The cmdlet joins the array into a single string with each element of the arrayseparated by a single space.

The outer quotes of the PowerShell strings aren't included when the ArgumentList values arepassed to the new process. If parameters or parameter values contain a space or quotes, they need tobe surrounded with escaped double quotes. For more information, seeabout_Quoting_Rules.

For the best results, use a single ArgumentList value containing all the arguments and anyneeded quote characters.

Type:String[]
Aliases:Args
Position:1
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

-Credential

Specifies a user account that has permission to perform this action. By default, the cmdlet uses thecredentials of the current user.

Type a user name, such as User01 or Domain01\User01, or enter a PSCredential objectgenerated by the Get-Credential cmdlet. If you type a user name, you're prompted to enter thepassword.

Credentials are stored in a PSCredentialobject and the password is stored as a SecureString.

Note

(Video) Microsoft PowerShell for Beginners - Video 1 Learn PowerShell

For more information about SecureString data protection, seeHow secure is SecureString?.

Type:PSCredential
Aliases:RunAs
Position:Named
Default value:Current user
Accept pipeline input:False
Accept wildcard characters:False

-FilePath

Specifies the optional path and filename of the program that runs in the process. Enter the name ofan executable file or of a document, such as a .txt or .doc file, that's associated with aprogram on the computer. This parameter is required.

If you specify only a filename that does not correspond to a system command, use theWorkingDirectory parameter to specify the path.

Type:String
Aliases:PSPath, Path
Position:0
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

-LoadUserProfile

Indicates that this cmdlet loads the Windows user profile stored in the HKEY_USERS registry keyfor the current user. The parameter doesn't apply to non-Windows systems.

This parameter doesn't affect the PowerShell profiles. For more information, seeabout_Profiles.

Type:SwitchParameter
Aliases:Lup
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

-NoNewWindow

Start the new process in the current console window. By default on Windows, PowerShell opens a newwindow. On non-Windows systems, you never get a new window.

You can't use the NoNewWindow and WindowStyle parameters in the same command.

The parameter doesn't apply to non-Windows systems.

Type:SwitchParameter
Aliases:nnw
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

-PassThru

Returns a process object for each process that the cmdlet started. By default, this cmdlet doesn'tgenerate any output.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

-RedirectStandardError

Specifies a file. This cmdlet sends any errors generated by the process to a file that you specify.Enter the path and filename. By default, the errors are displayed in the console.

Type:String
Aliases:RSE
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

-RedirectStandardInput

Specifies a file. This cmdlet reads input from the specified file. Enter the path and filename ofthe input file. By default, the process gets its input from the keyboard.

(Video) process cmdlets in PowerShell | Get-process | start-process

Type:String
Aliases:RSI
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

-RedirectStandardOutput

Specifies a file. This cmdlet sends the output generated by the process to a file that you specify.Enter the path and filename. By default, the output is displayed in the console.

Type:String
Aliases:RSO
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

-UseNewEnvironment

Indicates that this cmdlet uses new environment variables specified for the process. By default, thestarted process runs with the environment variables inherited from the parent process.

On Windows, when you use UseNewEnvironment, the new process starts only containing the defaultenvironment variables defined for the Machine scope. This has the side effect that the$env:USERNAME is set to SYSTEM. None of the variables from the User scope are included.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

-Verb

Specifies a verb to use when this cmdlet starts the process. The verbs that are available aredetermined by the filename extension of the file that runs in the process.

The following table shows the verbs for some common process file types.

File typeVerbs
.cmdEdit, Open, Print, RunAs, RunAsUser
.exeOpen, RunAs, RunAsUser
.txtOpen, Print, PrintTo
.wavOpen, Play

To find the verbs that can be used with the file that runs in a process, use the New-Object cmdletto create a System.Diagnostics.ProcessStartInfo object for the file. The available verbs are inthe Verbs property of the ProcessStartInfo object. For details, see the examples.

The parameter doesn't apply to non-Windows systems.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

-Wait

Indicates that this cmdlet waits for the specified process and its descendants to complete beforeaccepting more input. This parameter suppresses the command prompt or retains the window until theprocesses finish.

Type:SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet isn't run.

This parameter was introduced in PowerShell 6.0.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

-WindowStyle

Specifies the state of the window that's used for the new process. The default value is Normal.The acceptable values for this parameter are:

(Video) Run PowerShell When a Process Starts on Windows

  • Normal
  • Hidden
  • Minimized
  • Maximized

You can't use the WindowStyle and NoNewWindow parameters in the same command.

The parameter doesn't apply to non-Windows systems. When using on non-Windows systems, you neverget a new window.

Type:ProcessWindowStyle
Accepted values:Normal, Hidden, Minimized, Maximized
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

-WorkingDirectory

Specifies the location that the new process should start in.

When not specified, the cmdlet defaults to the fully-qualified location specified in theFilePath parameter. If the value of the FilePath parameter is not fully-qualified, itdefaults to the current working directory of the calling process.

Wildcards aren't supported. The path must not contain characters that would be interpreted aswildcards.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

Inputs

None

You can't pipe objects to this cmdlet.

Outputs

None

By default, this cmdlet returns no output.

Process

When you use the PassThru parameter, this cmdlet returns a Process object.

Notes

PowerShell includes the following aliases for Start-Process:

  • All platforms
    • saps
  • Windows
    • start

Native commands are executable files installed in the operating system. These executables can be runfrom any command-line shell, like PowerShell. Usually you run the command exactly as you would inbash or cmd.exe. The Start-Process cmdlet can be used to run any native commands, but shouldonly be used when you need to control how the command is executed.

Start-Process is useful for running GUI programs on non-Windows platforms. For example, runStart-Proces gedit to launch the graphical text editor common the GNOME Desktop environments.

By default, Start-Process launches a process asynchronously. Control is instantly returned toPowerShell even if the new process is still running.

  • On the local system, the launched process lives on independent from the calling process.
  • On a remote system, the new process is terminated when the remote session ends, immediatelyfollowing the Start-Process command. Therefore, you can't use Start-Process in a remotesession expecting the launched process to outlive the session.

If you do need to use Start-Process in a remote session, invoke it with the Wait parameter. Oryou could use other methods to create a new process on the remote system.

(Video) Starting and Stopping Processes With PowerShell

When using the Wait parameter, Start-Process waits for the process tree (the process and allits descendants) to exit before returning control. This is different than the behavior of theWait-Process cmdlet, which only waits for the specified processes to exit.

On Windows, the most common use case for Start-Process is to use the Wait parameter to blockprogress until the new process exits. On non-Windows system, this is rarely needed since the defaultbehavior for command-line applications is equivalent to Start-Process -Wait.

This cmdlet is implemented using the Start method of the System.Diagnostics.Processclass. For more information about this method, seeProcess.Start Method.

  • about_Quoting_Rules
  • Debug-Process
  • Get-Process
  • Start-Service
  • Stop-Process
  • Wait-Process

FAQs

What does start process do in PowerShell? ›

By default, Start-Process creates a new process that inherits all the environment variables that are defined in the current process. To specify the program that runs in the process, enter an executable file or script file, or a file that can be opened using a program on the computer.

How do I fix access denied in PowerShell? ›

Fix/Solution
  1. Ensure that you have opened the PowerShell with “Run as administrator” privilege.
  2. Ensure that you have passed input for the -Credential parameter and ensure the correct user credentials are provided.
  3. Set WMI Control permissions (in Remote computer)
  4. Add the user to the Local “Distributed COM Users” group.
Sep 14, 2022

How to bypass access denied in PowerShell? ›

Run Command Prompt and Windows PowerShell as Administrator
  1. Open Command Prompt as Administrator.
  2. Open Windows PowerShell as Administrator.
  3. Disable User Account Control Completely.
  4. Bypass UAC for Command Prompt and Windows PowerShell Only.
Feb 3, 2022

How do you Wait 10 seconds in PowerShell? ›

To pause the script for 10 seconds, I'd just use Start-Sleep -Second 10 . If I want to get anal about things, I could also specify the time in milliseconds as Start-Sleep -Milliseconds 10000.

How do I force a process to start? ›

  1. Click the Start menu.
  2. Click Run or in the search bar type services.msc.
  3. Press Enter.
  4. Look for the service and check the Properties and identify its service name.
  5. Once found, open a command prompt. Type sc queryex [servicename].
  6. Press Enter.
  7. Identify the PID.
  8. In the same command prompt type taskkill /pid [pid number] /f.
Sep 3, 2021

How does process start work? ›

Start(String, String) Starts a process resource by specifying the name of an application and a set of command-line arguments, and associates the resource with a new Process component.

How do I bypass Access Denied? ›

Right-click the file or folder, and then click Properties. Click the Security tab. Under Group or user names, click your name to see the permissions that you have. Click Edit, click your name, select the check boxes for the permissions that you must have, and then click OK.

How do I run PowerShell as administrator? ›

With Administrative privileges (Run as administrator)

Click Start, type PowerShell, right-click Windows PowerShell, and then click Run as administrator.

How do I unblock access denied? ›

The “Access Denied” error appears when your browser uses different proxy settings or VPN instead of what's really set on your Windows 10 PC.
...
You can try:
  1. Clearing your browser cookies and history.
  2. Turning off VPN and VPN extensions.
  3. Disabling your proxy.
  4. Switching to a premium VPN service.
  5. Resetting your browser data.

What is start service in PowerShell? ›

The Start-Service cmdlet sends a start message to the Windows Service Controller for each of the specified services. If a service is already running, the message is ignored without error.

What is process start event? ›

A process step start event represents the start of a subprocess or activity within a parent process and can be used to trigger step-based Service Level Criteria (SLC) rules. The step name is used to correlate start and end steps.

What does process mean in PowerShell? ›

The process block is where the work is done in a PowerShell advanced function. There are two different approaches we need to keep in mind and account for. The first is how you handle parameters and the second is pipeline input into your function.

What is start PowerShell in SQL Server? ›

You can start Windows PowerShell sessions from Object Explorer in SQL Server Management Studio (SSMS). SSMS launches Windows PowerShell, loads the SqlServer module, and sets the path context to the associated node in the Object Explorer tree. Note. There are two SQL Server PowerShell modules; SqlServer and SQLPS.

Videos

1. PowerShell Basics Get-Process Tutorial
(Robert McMillen)
2. PowerShell For Beginners Full Course | PowerShell Beginner tutorial Full Course
(Nerd's lesson)
3. Process Management in PowerShell | PowerShell Tutorial
(Scripting with Ease)
4. Powershell – “Start-Process” Alias
(Mahmood Shehab)
5. PowerShell Tutorial | Start-Process Part 4
(Technology Interpreters)
6. Windows PowerShell: Start-Job Cmdlet
(Skillsoft YouTube)
Top Articles
Latest Posts
Article information

Author: Ray Christiansen

Last Updated: 04/21/2023

Views: 6390

Rating: 4.9 / 5 (49 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Ray Christiansen

Birthday: 1998-05-04

Address: Apt. 814 34339 Sauer Islands, Hirtheville, GA 02446-8771

Phone: +337636892828

Job: Lead Hospitality Designer

Hobby: Urban exploration, Tai chi, Lockpicking, Fashion, Gunsmithing, Pottery, Geocaching

Introduction: My name is Ray Christiansen, I am a fair, good, cute, gentle, vast, glamorous, excited person who loves writing and wants to share my knowledge and understanding with you.