< Back
Stop-DbaProcess
Post
NAME Stop-DbaProcess
SYNOPSIS
This command finds and kills SQL Server processes.
SYNTAX
Stop-DbaProcess [-SqlCredential <Pscredential>] [-Spid <System.Int32[]>] [-ExcludeSpid <System.Int32[]>]
[-Database <System.String[]>] [-Login <System.String[]>] [-Hostname <System.String[]>] [-Program
<System.String[]>] [-EnableException <Switch>] [<CommonParameters>]
Stop-DbaProcess -SqlInstance <DbaInstanceParameter> [-SqlCredential <Pscredential>] [-Spid <System.Int32[]>]
[-ExcludeSpid <System.Int32[]>] [-Database <System.String[]>] [-Login <System.String[]>] [-Hostname
<System.String[]>] [-Program <System.String[]>] [-EnableException <Switch>] [<CommonParameters>]
Stop-DbaProcess [-SqlCredential <Pscredential>] [-Spid <System.Int32[]>] [-ExcludeSpid <System.Int32[]>]
[-Database <System.String[]>] [-Login <System.String[]>] [-Hostname <System.String[]>] [-Program
<System.String[]>] -InputObject <System.Object[]> [-EnableException <Switch>] [<CommonParameters>]
DESCRIPTION
This command kills all spids associated with a spid, login, host, program or database.
If you are attempting to kill your own login sessions, the process performing the kills will be skipped.
PARAMETERS
-Database [<System.String[]>]
Specifies one or more databases whose processes will be killed. Options for this parameter are auto-populated
from the server and only databases that have active processes are offered.
This parameter is auto-populated from -SqlInstance and allows only database names that have active processes.
You can specify one or more Databases whose processes will be killed.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-EnableException [<Switch>]
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables
advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own
try/catch.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ExcludeSpid [<System.Int32[]>]
Specifies one or more spids which will not be killed. Options for this parameter are auto-populated from the
server.
Exclude is the last filter to run, so even if a spid matches (for example) Hosts, if it's listed in Exclude it
wil be excluded.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Hostname [<System.String[]>]
Specifies one or more client hostnames whose processes will be killed. Options for this parameter are
auto-populated from the server and only hostnames that have active processes are offered.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-InputObject [<System.Object[]>]
This is the process object passed by Get-DbaProcess if using a pipeline.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Login [<System.String[]>]
Specifies one or more login names whose processes will be killed. Options for this parameter are
auto-populated from the server and only login names that have active processes are offered.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Program [<System.String[]>]
Specifies one or more client programs whose processes will be killed. Options for this parameter are
auto-populated from the server and only programs that have active processes are offered.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Spid [<System.Int32[]>]
Specifies one or more spids to be killed. Options for this parameter are auto-populated from the server.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlCredential [<Pscredential>]
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory -
Integrated are all supported.
For MFA support, please use Connect-DbaInstance.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlInstance [<DbaInstanceParameter>]
The target SQL Server instance or instances.
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, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
NOTES
Tags: Processes
Author: Chrissy LeMaire (@cl), netnerds.net
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Stop-DbaProcess -SqlInstance sqlserver2014a -Login base\\ctrlb, sa
Finds all processes for base\\ctrlb and sa on sqlserver2014a, then kills them. Uses Windows Authentication to login
to sqlserver2014a.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Stop-DbaProcess -SqlInstance sqlserver2014a -SqlCredential $credential -Spid 56, 77
Finds processes for spid 56 and 57, then kills them. Uses alternative (SQL or Windows) credentials to login to
sqlserver2014a.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Stop-DbaProcess -SqlInstance sqlserver2014a -Program 'Microsoft SQL Server Management Studio'
Finds processes that were created in Microsoft SQL Server Management Studio, then kills them.
-------------------------- EXAMPLE 4 --------------------------
PS C:\\>Stop-DbaProcess -SqlInstance sqlserver2014a -Hostname workstationx, server100
Finds processes that were initiated (computers/clients) workstationx and server 1000, then kills them.
-------------------------- EXAMPLE 5 --------------------------
PS C:\\>Stop-DbaProcess -SqlInstance sqlserver2014 -Database tempdb -WhatIf
Shows what would happen if the command were executed.
-------------------------- EXAMPLE 6 --------------------------
PS C:\\>Get-DbaProcess -SqlInstance sql2016 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess
Finds processes that were created with dbatools, then kills them.
RELATED LINKS
https://dbatools.io/Stop-DbaProcess
SYNOPSIS
This command finds and kills SQL Server processes.
SYNTAX
Stop-DbaProcess [-SqlCredential <Pscredential>] [-Spid <System.Int32[]>] [-ExcludeSpid <System.Int32[]>]
[-Database <System.String[]>] [-Login <System.String[]>] [-Hostname <System.String[]>] [-Program
<System.String[]>] [-EnableException <Switch>] [<CommonParameters>]
Stop-DbaProcess -SqlInstance <DbaInstanceParameter> [-SqlCredential <Pscredential>] [-Spid <System.Int32[]>]
[-ExcludeSpid <System.Int32[]>] [-Database <System.String[]>] [-Login <System.String[]>] [-Hostname
<System.String[]>] [-Program <System.String[]>] [-EnableException <Switch>] [<CommonParameters>]
Stop-DbaProcess [-SqlCredential <Pscredential>] [-Spid <System.Int32[]>] [-ExcludeSpid <System.Int32[]>]
[-Database <System.String[]>] [-Login <System.String[]>] [-Hostname <System.String[]>] [-Program
<System.String[]>] -InputObject <System.Object[]> [-EnableException <Switch>] [<CommonParameters>]
DESCRIPTION
This command kills all spids associated with a spid, login, host, program or database.
If you are attempting to kill your own login sessions, the process performing the kills will be skipped.
PARAMETERS
-Database [<System.String[]>]
Specifies one or more databases whose processes will be killed. Options for this parameter are auto-populated
from the server and only databases that have active processes are offered.
This parameter is auto-populated from -SqlInstance and allows only database names that have active processes.
You can specify one or more Databases whose processes will be killed.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-EnableException [<Switch>]
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables
advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own
try/catch.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ExcludeSpid [<System.Int32[]>]
Specifies one or more spids which will not be killed. Options for this parameter are auto-populated from the
server.
Exclude is the last filter to run, so even if a spid matches (for example) Hosts, if it's listed in Exclude it
wil be excluded.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Hostname [<System.String[]>]
Specifies one or more client hostnames whose processes will be killed. Options for this parameter are
auto-populated from the server and only hostnames that have active processes are offered.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-InputObject [<System.Object[]>]
This is the process object passed by Get-DbaProcess if using a pipeline.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Login [<System.String[]>]
Specifies one or more login names whose processes will be killed. Options for this parameter are
auto-populated from the server and only login names that have active processes are offered.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Program [<System.String[]>]
Specifies one or more client programs whose processes will be killed. Options for this parameter are
auto-populated from the server and only programs that have active processes are offered.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Spid [<System.Int32[]>]
Specifies one or more spids to be killed. Options for this parameter are auto-populated from the server.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlCredential [<Pscredential>]
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory -
Integrated are all supported.
For MFA support, please use Connect-DbaInstance.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlInstance [<DbaInstanceParameter>]
The target SQL Server instance or instances.
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, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
NOTES
Tags: Processes
Author: Chrissy LeMaire (@cl), netnerds.net
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Stop-DbaProcess -SqlInstance sqlserver2014a -Login base\\ctrlb, sa
Finds all processes for base\\ctrlb and sa on sqlserver2014a, then kills them. Uses Windows Authentication to login
to sqlserver2014a.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Stop-DbaProcess -SqlInstance sqlserver2014a -SqlCredential $credential -Spid 56, 77
Finds processes for spid 56 and 57, then kills them. Uses alternative (SQL or Windows) credentials to login to
sqlserver2014a.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Stop-DbaProcess -SqlInstance sqlserver2014a -Program 'Microsoft SQL Server Management Studio'
Finds processes that were created in Microsoft SQL Server Management Studio, then kills them.
-------------------------- EXAMPLE 4 --------------------------
PS C:\\>Stop-DbaProcess -SqlInstance sqlserver2014a -Hostname workstationx, server100
Finds processes that were initiated (computers/clients) workstationx and server 1000, then kills them.
-------------------------- EXAMPLE 5 --------------------------
PS C:\\>Stop-DbaProcess -SqlInstance sqlserver2014 -Database tempdb -WhatIf
Shows what would happen if the command were executed.
-------------------------- EXAMPLE 6 --------------------------
PS C:\\>Get-DbaProcess -SqlInstance sql2016 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess
Finds processes that were created with dbatools, then kills them.
RELATED LINKS
https://dbatools.io/Stop-DbaProcess