< Back

Get-DbaProcess

Mon Jan 13, 2020 11:28 am

NAME Get-DbaProcess



SYNOPSIS

This command displays SQL Server processes.





SYNTAX

Get-DbaProcess [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]> [[-SqlCredential]

<Pscredential>] [[-Spid] <System.Int32[]>] [[-ExcludeSpid] <System.Int32[]>] [[-Database] <System.String[]>]

[[-Login] <System.String[]>] [[-Hostname] <System.String[]>] [[-Program] <System.String[]>] [-ExcludeSystemSpids

<Switch>] [-EnableException <Switch>] [<CommonParameters>]





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- ... tion-leaks for

the query to get the last executed SQL statement, minutesasleep and host process ID.





PARAMETERS

-Database [<System.String[]>]

Specifies one or more databases with active processes to look for. Options for this parameter are

auto-populated from the server.



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 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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ExcludeSystemSpids [<Switch>]

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



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Hostname [<System.String[]>]

Specifies one or more hostnames with active processes to look for. Options for this parameter are

auto-populated from the server.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Login [<System.String[]>]

Specifies one or more Login names with active processes to look for. Options for this parameter are

auto-populated from the server.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Program [<System.String[]>]

Specifies one or more program names with active processes to look for. Options for this parameter are

auto-populated from the server.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Spid [<System.Int32[]>]

Specifies one or more process IDs (Spid) to be displayed. 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 [<Sqlcollaborative.Dbatools.Parameter.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: Process, Session, ActivityMonitor

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:\\>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.



RELATED LINKS

https://dbatools.io/Get-DbaProcess