powershellscripts.com

Tutorials  PowerShell Cmdlet Help for Stop-Process



NAME
Stop-Process

SYNOPSIS
Stops one or more running processes.

SYNTAX
Stop-Process [-Id] [-Force] [-PassThru] [-Confirm] [-WhatIf] []

Stop-Process -InputObject [-Force] [-PassThru] [-Confirm] [-WhatIf] []

Stop-Process -Name [-Force] [-PassThru] [-Confirm] [-WhatIf] []


DESCRIPTION
The Stop-Process cmdlet stops one or more running processes. You can specify a process by process name or process I
D (PID), or pass a process object to Stop-Process. Stop-Process works only on processes running on the local compu
ter.

On Windows Vista and later versions of Windows, to stop a process that is not owned by the current user, you must s
tart Windows PowerShell with the "Run as administrator" option. Also, you are prompted for confirmation unless you
use the Force parameter.


PARAMETERS
-Force []
Stops the specified processes without prompting for confirmation. By default, Stop-Process prompts for confirma
tion before stopping any process that is not owned by the current user.

To find the owner of a process, use the Get-WmiMethod cmdlet to get a Win32_Process object that represents the
process, and then use the GetOwner method of the object.

Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false

-Id
Specifies the process IDs of the processes to be stopped. To specify multiple IDs, use commas to separate the I
Ds. To find the PID of a process, type "get-process". The parameter name ("Id") is optional.

Required? true
Position? 1
Default value
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? false

-InputObject
Stops the processes represented by the specified process objects. Enter a variable that contains the objects, o
r type a command or expression that gets the objects.

Required? true
Position? named
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false

-Name
Specifies the process names of the processes to be stopped. You can type multiple process names (separated by c
ommas) or use wildcard characters.

Required? true
Position? named
Default value
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? false

-PassThru []
Returns an object representing the process. By default, this cmdlet does not generate any output.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-Confirm []
Prompts you for confirmation before executing the command.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-WhatIf []
Describes what would happen if you executed the command without actually executing the command.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false


This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer and OutVariable. For more information, type,
"get-help about_commonparameters".

INPUTS
System.Diagnostics.Process
You can pipe a process object to Stop-Process.


OUTPUTS
None or System.Diagnostics.Process
When you use the PassThru parameter, Stop-Process returns a System.Diagnostics.Process object that represents t
he stopped process. Otherwise, this cmdlet does not generate any output.


NOTES


You can also refer to Stop-Process by its built-in aliases, "kill" and "spps". For more information, see about_
Aliases.

You can also use the properties and methods of the Windows Management Instrumentation (WMI) Win32_Process objec
t in Windows PowerShell. For more information, see Get-WmiObject and the WMI SDK.

When stopping processes, be aware that stopping a process can stop process and services that depend on the proc
ess. In an extreme case, stopping a process can stop Windows.


-------------------------- EXAMPLE 1 --------------------------

C:\PS>stop-process -name notepad


Description
-----------
This command stops all instances of the Notepad process on the computer. (Each instance of Notepad runs in its own
process.) It uses the Name parameter to specify the processes, all of which have the same name. If you were to use
the ID parameter to stop the same processes, you would have to list the process IDs of each instance of Notepad.





-------------------------- EXAMPLE 2 --------------------------

C:\PS>stop-process -id 3952 -confirm -passthru

Confirm
Are you sure you want to perform this action?
Performing operation "Stop-Process" on Target "notepad (3952)".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help
(default is "Y"):y
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
------- ------ ----- ----- ----- ------ -- -----------
41 2 996 3212 31 3952 notepad


Description
-----------
This command stops a particular instance of the Notepad process. It uses the process ID, 3952, to identify the proc
ess. The Confirm parameter directs Windows PowerShell to prompt the user before stopping the process. Because the p
rompt includes the process name, as well as its ID, this is best practice. The PassThru parameter passes the proces
s object to the formatter for display. Without this parameter, there would be no display after a Stop-Process comma
nd.





-------------------------- EXAMPLE 3 --------------------------

C:\PS>calc

c:\PS>$p = get-process calc

c:\PS>stop-process -inputobject $p

c:\PS>get-process | where-object {$_.HasExited}


Description
-----------
This series of commands starts and stops the Calc process and then detects processes that have stopped.

The first command ("calc") starts an instance of the calculator. The second command ("$p = get-process calc"), uses
the Get-Process cmdlet to get an object representing the Calc process and store it in the $p variable. The third c
ommand ("stop-process -inputobject $p") uses the Stop-Process cmdlet to stop the Calc process. It uses the InputObj
ect parameter to pass the object to Stop-Process.

The last command gets all of the processes on the computer that were running but that are now stopped. It uses the
Get-Process cmdlet to get all of the processes on the computer. The pipeline operator (|) passes the results to the
Where-Object cmdlet, which selects the ones where the value of the HasExited property is TRUE. HasExited is just o
ne property of process objects. To find all the properties, type "get-process | get-member".





-------------------------- EXAMPLE 4 --------------------------

C:\PS>get-process lsass | stop-process

Stop-Process : Cannot stop process 'lsass (596)' because of the following error: Access is denied
At line:1 char:34
+ get-process lsass | stop-process <<<<

[ADMIN]: C:\PS> get-process lsass | stop-process
Warning!
Are you sure you want to perform this action?
Performing operation 'Stop-Process' on Target 'lsass(596)'
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):

[ADMIN]: C:\PS> get-process lsass | stop-process -force
[ADMIN]: C:\PS>


Description
-----------
These commands show the effect of using the Force parameter to stop a process that is not owned by the user.

The first command uses the Get-Process cmdlet to get the Lsass process. A pipeline operator sends the process to th
e Stop-Process cmdlet to stop it. As shown in the sample output, the first command fails with an "Access denied" me
ssage, because this process can be stopped only by a member of the Administrator's group on the computer.

When Windows PowerShell is opened with the "Run as administrator" option, and the command is repeated, Windows Powe
rShell prompts you for confirmation.

The second command uses the Force parameter to suppress the prompt. As a result, the process is stopped without con
firmation.






RELATED LINKS
Online version: http://go.microsoft.com/fwlink/?LinkID=113412
Get-Process
Start-Process
Stop-Process
Wait-Process
Debug-Process