Stop-Process
Additional Resources for Stop-Process |
Terminating a Process http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/stop-process.mspx
|
SYNOPSIS
Stops one or more running processes.
SYNTAX
Stop-Process [-id] <Int32[]> [-passThru] [-whatIf] [-confirm] [<CommonParameters>]
Stop-Process -name <string[]> [-passThru] [-whatIf] [-confirm] [<CommonParameters>]
Stop-Process -inputObject <Process[]> [-passThru] [-whatIf] [-confirm] [<CommonParameters>]
DETAILED DESCRIPTION
The Stop-Process cmdlet stops one or more running processes. You can specify a process by process name or process ID (PID), or pass a process object to Stop-Process. For Get-Process, the default method is by process name. For Stop-Process, the default method is by process ID.
PARAMETERS
-id <Int32[]>
Specifies the process IDs of the processes to be stopped. To specify multiple IDs, use commas to separate the IDs. To find the PID of a process, type "get-process". The parameter name ("-Id") is optional.
Required? |
true |
Position? |
1 |
Default value |
Null |
Accept pipeline input? |
true (ByPropertyName) |
Accept wildcard characters? |
false |
-inputObject <Process[]>
Stops the processes represented by the specified process objects. Enter a variable that contains the objects or 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 <string[]>
Specifies the process names of the processes to be stopped. You can type multiple process names (separated by commas) or use wildcard characters.
Required? |
true |
Position? |
named |
Default value |
Null |
Accept pipeline input? |
true (ByPropertyName) |
Accept wildcard characters? |
true |
-passThru <SwitchParameter>
Passes the object created by this cmdlet through the pipeline. By default, this cmdlet does not pass any objects through the pipeline.
Required? |
false |
Position? |
named |
Default value |
False |
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 |
-confirm
Prompts you for confirmation before executing the command.
Required? |
false |
Position? |
named |
Default value |
|
Accept pipeline input? |
false |
Accept wildcard characters? |
false |
<CommonParameters>
This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable. For more information, type, "get-help about_commonparameters".
INPUT TYPE
PSObjects with the "Name" or "Id" property specified, or strings, or integers.
RETURN TYPE
None by default. When -passthru is specified, a PSObject is passed through. the pipeline.
NOTES
For more information, type "Get-Help Stop-Process -detailed". For technical information, type "Get-Help Stop-Process -full".
When specifying multiple values for a parameter, use commas to separate the values. For example, "<parameter-name> <value1>, <value2>".
You can also use the properties and methods of the WMI Win32_Process object in Windows PowerShell. For information, see Get-WmiObjectand the Windows Management Instrument SDK.
You can also refer to Stop-Process by its built-in aliases, "kill" and "spps". For more information, see About_Alias.
When stopping processes, be aware that some processes are dependent upon others, and might stop when the process that they depend upon stops. In an extreme case, stopping a process can stop Windows.
EXAMPLE 1
stop-process -name notepad
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
stop-process -id 3952 -confirm -passthru
This command stops a particular instance of the Notepad process. It uses the process ID, 3952, to identify the process. The Confirm parameter directs Windows PowerShell to prompt the user before stopping the process. Because the prompt includes the process name, as well as its ID, this is best practice. The Passthru parameter passes the process object to the formatter for display. Without this parameter, there would be no display after a Stop-Process command.
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 321 23 139 52 notepad
EXAMPLE 3
calc
$p = get-process calc
stop-process -inputobject $p
get-process | where-object {$_.HasExited}
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-Processcmdlet to get an object representing the Calc process and store it in the $p variable. The third command ("stop-process -inputobject $p") uses the Stop-Process cmdlet to stop the Calc process. It uses the InputObject parameter to pass the object to Stop-Process.
The last command gets all of the process on the computer that were running, but 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 -Objectcmdlet which selects the ones where the value of the HasExited property is TRUE. HasExited is just one property of process objects. To find all properties, type "get-process | get-member".
RELATED LINKS