commands

^

Get-DbaProcess

Author Chrissy LeMaire (@cl), netnerds.net
Availability Windows, Linux, macOS

 

Want to see the source code for this command? Check out Get-DbaProcess on GitHub.
Want to see the Bill Of Health for this command? Check out Get-DbaProcess.

Synopsis

This command displays SQL Server processes.

Description

This command displays processes associated with a spid, login, host, program or database.

Thanks to Michael J Swart at https://sqlperformance.com/2017/07/sql-performance/find-database-connection-leaks for the query to get the last executed SQL statement, minutesasleep and host process ID.

Syntax

Get-DbaProcess
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-Spid] <Int32[]>]
    [[-ExcludeSpid] <Int32[]>]
    [[-Database] <String[]>]
    [[-Login] <String[]>]
    [[-Hostname] <String[]>]
    [[-Program] <String[]>]
    [-ExcludeSystemSpids]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
PS C:\> Get-DbaProcess -SqlInstance sqlserver2014a -Login base\ctrlb, sa

Shows information about the processes for base\ctrlb and sa on sqlserver2014a. Windows Authentication is used in connecting to sqlserver2014a.

Example: 2
PS C:\> Get-DbaProcess -SqlInstance sqlserver2014a -SqlCredential $credential -Spid 56, 77

Shows information about the processes for spid 56 and 57. Uses alternative (SQL or Windows) credentials to authenticate to sqlserver2014a.

Example: 3
PS C:\> Get-DbaProcess -SqlInstance sqlserver2014a -Program 'Microsoft SQL Server Management Studio'

Shows information about the processes that were created in Microsoft SQL Server Management Studio.

Example: 4
PS C:\> Get-DbaProcess -SqlInstance sqlserver2014a -Host workstationx, server100

Shows information about the processes that were initiated by hosts (computers/clients) workstationx and server 1000.

Required Parameters

-SqlInstance

The target SQL Server instance or instances.

Alias
Required True
Pipeline true (ByValue)
Default Value

Optional Parameters

-SqlCredential

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.

Alias
Required False
Pipeline false
Default Value
-Spid

Specifies one or more process IDs (Spid) to be displayed. Options for this parameter are auto-populated from the server.

Alias
Required False
Pipeline false
Default Value
-ExcludeSpid

Specifies one ore more process IDs to exclude from display. Options for this parameter are auto-populated from the server.
This is the last filter to run, so even if a Spid matches another filter, it will be excluded by this filter.

Alias
Required False
Pipeline false
Default Value
-Database

Specifies one or more databases with active processes to look for. Options for this parameter are auto-populated from the server.

Alias
Required False
Pipeline false
Default Value
-Login

Specifies one or more Login names with active processes to look for. Options for this parameter are auto-populated from the server.

Alias
Required False
Pipeline false
Default Value
-Hostname

Specifies one or more hostnames with active processes to look for. Options for this parameter are auto-populated from the server.

Alias
Required False
Pipeline false
Default Value
-Program

Specifies one or more program names with active processes to look for. Options for this parameter are auto-populated from the server.

Alias
Required False
Pipeline false
Default Value
-ExcludeSystemSpids

If this switch is enabled, system Spids will be ignored.

Alias
Required False
Pipeline false
Default Value False
-EnableException

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.

Alias
Required False
Pipeline false
Default Value False