< Back
Invoke-DbaWhoIsActive
Post
NAME Invoke-DbaWhoIsActive
SYNOPSIS
Outputs results of Adam Machanic's sp_WhoIsActive DataTable
SYNTAX
Invoke-DbaWhoIsActive [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>
[[-SqlCredential] <Pscredential>] [[-Database] <System.Object>] [[-Filter] <String>] [[-FilterType] <String>]
[[-NotFilter] <String>] [[-NotFilterType] <String>] [-ShowOwnSpid <Switch>] [-ShowSystemSpids <Switch>]
[[-ShowSleepingSpids] <Int>] [-GetFullInnerText <Switch>] [[-GetPlans] <Int>] [-GetOuterCommand <Switch>]
[-GetTransactionInfo <Switch>] [[-GetTaskInfo] <Int>] [-GetLocks <Switch>] [-GetAverageTime <Switch>]
[-GetAdditonalInfo <Switch>] [-FindBlockLeaders <Switch>] [[-DeltaInterval] <Int>] [[-OutputColumnList] <String>]
[[-SortOrder] <String>] [[-FormatOutput] <Int>] [[-DestinationTable] <String>] [-ReturnSchema <Switch>] [[-Schema]
<String>] [-Help <Switch>] [-EnableException <Switch>] [<CommonParameters>]
DESCRIPTION
Output results of Adam Machanic's sp_WhoIsActive
This command was built with Adam's permission. To read more about sp_WhoIsActive, please visit:
Updates: http://sqlblog.com/blogs/adam_machanic/ ... fault.aspx
Also, consider donating to Adam if you find this stored procedure helpful: http://tinyurl.com/WhoIsActiveDonate
PARAMETERS
-Database [<System.Object>]
The database where sp_WhoIsActive is installed. Defaults to master. If the sp_WhoIsActive is not installed,
the command will warn and exit.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-DeltaInterval [<Int>]
Pull deltas on various metrics
Interval in seconds to wait before doing the second data pull
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-DestinationTable [<String>]
If set to a non-blank value, the script will attempt to insert into the specified destination table. Please
note that the script will not verify that the table exists, or that it has the correct schema, before doing
the insert. Table can be specified in one, two, or three-part format
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
-Filter [<String>]
FiltersBoth inclusive and exclusive
Set either filter to '' to disable
Session is a session ID, and either 0 or '' can be used to indicate "all" sessions
All other filter types support % or _ as wildcards
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-FilterType [<String>]
Valid filter types are: session, program, database, login, and host
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-FindBlockLeaders [<Switch>]
Walk the blocking chain and count the number of
total SPIDs blocked all the way down by a given session
Also enables task_info Level 1, if @get_task_info is set to 0
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-FormatOutput [<Int>]
Formats some of the output columns in a more "human readable" form
0 disables output format
1 formats the output for variable-width fonts
2 formats the output for fixed-width fonts
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-GetAdditonalInfo [<Switch>]
Get additional non-performance-related information about the session or request text_size, language,
date_format, date_first, quoted_identifier, arithabort, ansi_null_dflt_on, ansi_defaults, ansi_warnings,
ansi_padding, ansi_nulls, concat_null_yields_null, transaction_isolation_level, lock_timeout,
deadlock_priority, row_count, command_type
If a SQL Agent job is running, an subnode called agent_info will be populated with some or all of the
following: job_id, job_name, step_id, step_name, msdb_query_error (in the event of an error)
If @get_task_info is set to 2 and a lock wait is detected, a subnode called block_info will be populated with
some or all of the following: lock_type, database_name, object_id, file_id, hobt_id, applock_hash,
metadata_resource, metadata_class_id, object_name, schema_name
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-GetAverageTime [<Switch>]
Get average time for past runs of an active query
(based on the combination of plan handle, sql handle, and offset)
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-GetFullInnerText [<Switch>]
If 1, gets the full stored procedure or running batch, when available
If 0, gets only the actual statement that is currently running in the batch or procedure
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-GetLocks [<Switch>]
Gets associated locks for each request, aggregated in an XML format
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-GetOuterCommand [<Switch>]
Get the associated outer ad hoc query or stored procedure call, if available
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-GetPlans [<Int>]
Get associated query plans for running tasks, if available
If 1, gets the plan based on the request's statement offset
If 2, gets the entire plan based on the request's plan_handle
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-GetTaskInfo [<Int>]
Get information on active tasks, based on three interest levels
Level 0 does not pull any task-related information
Level 1 is a lightweight mode that pulls the top non-CXPACKET wait, giving preference to blockers
Level 2 pulls all available task-based metrics, including:
number of active tasks, current wait stats, physical I/O, context switches, and blocker information
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-GetTransactionInfo [<Switch>]
Enables pulling transaction log write info and transaction duration
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Help [<Switch>]
Help! What do I do?
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-NotFilter [<String>]
FiltersBoth inclusive and exclusive
Set either filter to '' to disable
Session is a session ID, and either 0 or '' can be used to indicate "all" sessions
All other filter types support % or _ as wildcards
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-NotFilterType [<String>]
Valid filter types are: session, program, database, login, and host
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-OutputColumnList [<String>]
List of desired output columns, in desired order
Note that the final output will be the intersection of all enabled features and all columns in the list.
Therefore, only columns associated with enabled features will actually appear in the output. Likewise,
removing columns from this list may effectively disable features, even if they are turned on
Each element in this list must be one of the valid output column names. Names must be delimited by square
brackets. White space, formatting, and additional characters are allowed, as long as the list contains exact
matches of delimited valid column names.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ReturnSchema [<Switch>]
If set to 1, no data collection will happen and no result set will be returned; instead, a CREATE TABLE
statement will be returned via the @schema parameter, which will match the schema of the result set that would
be returned by using the same collection of the rest of the parameters. The CREATE TABLE statement will have a
placeholder token of <table_name> in place of an actual table name.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Schema [<String>]
If set to 1, no data collection will happen and no result set will be returned; instead, a CREATE TABLE
statement will be returned via the @schema parameter, which will match the schema of the result set that would
be returned by using the same collection of the rest of the parameters. The CREATE TABLE statement will have a
placeholder token of <table_name> in place of an actual table name.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ShowOwnSpid [<Switch>]
Retrieve data about the calling session?
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ShowSleepingSpids [<Int>]
Controls how sleeping SPIDs are handled, based on the idea of levels of interest
0 does not pull any sleeping SPIDs
1 pulls only those sleeping SPIDs that also have an open transaction
2 pulls all sleeping SPIDs
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ShowSystemSpids [<Switch>]
Retrieve data about system sessions?
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SortOrder [<String>]
Column(s) by which to sort output, optionally with sort directions.
Valid column choices:
session_id, physical_io, reads, physical_reads, writes, tempdb_allocations,
tempdb_current, CPU, context_switches, used_memory, physical_io_delta,
reads_delta, physical_reads_delta, writes_delta, tempdb_allocations_delta,
tempdb_current_delta, CPU_delta, context_switches_delta, used_memory_delta,
tasks, tran_start_time, open_tran_count, blocking_session_id, blocked_session_count,
percent_complete, host_name, login_name, database_name, start_time, login_time
Note that column names in the list must be bracket-delimited. Commas and/or white space are not required.
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. You must have sysadmin access and server version must be SQL
Server version 2000 or higher.
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: Community, WhoIsActive
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
http://whoisactive.com
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Invoke-DbaWhoIsActive -SqlInstance sqlserver2014a
Execute sp_whoisactive on sqlserver2014a. This command expects sp_WhoIsActive to be in the master database. Logs
into the SQL Server with Windows credentials.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Invoke-DbaWhoIsActive -SqlInstance sqlserver2014a -SqlCredential $credential -Database dbatools
Execute sp_whoisactive on sqlserver2014a. This command expects sp_WhoIsActive to be in the dbatools database. Logs
into the SQL Server with SQL Authentication.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Invoke-DbaWhoIsActive -SqlInstance sqlserver2014a -GetAverageTime
Similar to running sp_WhoIsActive @get_avg_time
-------------------------- EXAMPLE 4 --------------------------
PS C:\\>Invoke-DbaWhoIsActive -SqlInstance sqlserver2014a -GetOuterCommand -FindBlockLeaders
Similar to running sp_WhoIsActive @get_outer_command = 1, @find_block_leaders = 1
RELATED LINKS
https://dbatools.io/Invoke-DbaWhoIsActive
SYNOPSIS
Outputs results of Adam Machanic's sp_WhoIsActive DataTable
SYNTAX
Invoke-DbaWhoIsActive [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>
[[-SqlCredential] <Pscredential>] [[-Database] <System.Object>] [[-Filter] <String>] [[-FilterType] <String>]
[[-NotFilter] <String>] [[-NotFilterType] <String>] [-ShowOwnSpid <Switch>] [-ShowSystemSpids <Switch>]
[[-ShowSleepingSpids] <Int>] [-GetFullInnerText <Switch>] [[-GetPlans] <Int>] [-GetOuterCommand <Switch>]
[-GetTransactionInfo <Switch>] [[-GetTaskInfo] <Int>] [-GetLocks <Switch>] [-GetAverageTime <Switch>]
[-GetAdditonalInfo <Switch>] [-FindBlockLeaders <Switch>] [[-DeltaInterval] <Int>] [[-OutputColumnList] <String>]
[[-SortOrder] <String>] [[-FormatOutput] <Int>] [[-DestinationTable] <String>] [-ReturnSchema <Switch>] [[-Schema]
<String>] [-Help <Switch>] [-EnableException <Switch>] [<CommonParameters>]
DESCRIPTION
Output results of Adam Machanic's sp_WhoIsActive
This command was built with Adam's permission. To read more about sp_WhoIsActive, please visit:
Updates: http://sqlblog.com/blogs/adam_machanic/ ... fault.aspx
Also, consider donating to Adam if you find this stored procedure helpful: http://tinyurl.com/WhoIsActiveDonate
PARAMETERS
-Database [<System.Object>]
The database where sp_WhoIsActive is installed. Defaults to master. If the sp_WhoIsActive is not installed,
the command will warn and exit.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-DeltaInterval [<Int>]
Pull deltas on various metrics
Interval in seconds to wait before doing the second data pull
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-DestinationTable [<String>]
If set to a non-blank value, the script will attempt to insert into the specified destination table. Please
note that the script will not verify that the table exists, or that it has the correct schema, before doing
the insert. Table can be specified in one, two, or three-part format
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
-Filter [<String>]
FiltersBoth inclusive and exclusive
Set either filter to '' to disable
Session is a session ID, and either 0 or '' can be used to indicate "all" sessions
All other filter types support % or _ as wildcards
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-FilterType [<String>]
Valid filter types are: session, program, database, login, and host
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-FindBlockLeaders [<Switch>]
Walk the blocking chain and count the number of
total SPIDs blocked all the way down by a given session
Also enables task_info Level 1, if @get_task_info is set to 0
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-FormatOutput [<Int>]
Formats some of the output columns in a more "human readable" form
0 disables output format
1 formats the output for variable-width fonts
2 formats the output for fixed-width fonts
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-GetAdditonalInfo [<Switch>]
Get additional non-performance-related information about the session or request text_size, language,
date_format, date_first, quoted_identifier, arithabort, ansi_null_dflt_on, ansi_defaults, ansi_warnings,
ansi_padding, ansi_nulls, concat_null_yields_null, transaction_isolation_level, lock_timeout,
deadlock_priority, row_count, command_type
If a SQL Agent job is running, an subnode called agent_info will be populated with some or all of the
following: job_id, job_name, step_id, step_name, msdb_query_error (in the event of an error)
If @get_task_info is set to 2 and a lock wait is detected, a subnode called block_info will be populated with
some or all of the following: lock_type, database_name, object_id, file_id, hobt_id, applock_hash,
metadata_resource, metadata_class_id, object_name, schema_name
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-GetAverageTime [<Switch>]
Get average time for past runs of an active query
(based on the combination of plan handle, sql handle, and offset)
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-GetFullInnerText [<Switch>]
If 1, gets the full stored procedure or running batch, when available
If 0, gets only the actual statement that is currently running in the batch or procedure
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-GetLocks [<Switch>]
Gets associated locks for each request, aggregated in an XML format
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-GetOuterCommand [<Switch>]
Get the associated outer ad hoc query or stored procedure call, if available
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-GetPlans [<Int>]
Get associated query plans for running tasks, if available
If 1, gets the plan based on the request's statement offset
If 2, gets the entire plan based on the request's plan_handle
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-GetTaskInfo [<Int>]
Get information on active tasks, based on three interest levels
Level 0 does not pull any task-related information
Level 1 is a lightweight mode that pulls the top non-CXPACKET wait, giving preference to blockers
Level 2 pulls all available task-based metrics, including:
number of active tasks, current wait stats, physical I/O, context switches, and blocker information
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-GetTransactionInfo [<Switch>]
Enables pulling transaction log write info and transaction duration
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Help [<Switch>]
Help! What do I do?
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-NotFilter [<String>]
FiltersBoth inclusive and exclusive
Set either filter to '' to disable
Session is a session ID, and either 0 or '' can be used to indicate "all" sessions
All other filter types support % or _ as wildcards
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-NotFilterType [<String>]
Valid filter types are: session, program, database, login, and host
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-OutputColumnList [<String>]
List of desired output columns, in desired order
Note that the final output will be the intersection of all enabled features and all columns in the list.
Therefore, only columns associated with enabled features will actually appear in the output. Likewise,
removing columns from this list may effectively disable features, even if they are turned on
Each element in this list must be one of the valid output column names. Names must be delimited by square
brackets. White space, formatting, and additional characters are allowed, as long as the list contains exact
matches of delimited valid column names.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ReturnSchema [<Switch>]
If set to 1, no data collection will happen and no result set will be returned; instead, a CREATE TABLE
statement will be returned via the @schema parameter, which will match the schema of the result set that would
be returned by using the same collection of the rest of the parameters. The CREATE TABLE statement will have a
placeholder token of <table_name> in place of an actual table name.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Schema [<String>]
If set to 1, no data collection will happen and no result set will be returned; instead, a CREATE TABLE
statement will be returned via the @schema parameter, which will match the schema of the result set that would
be returned by using the same collection of the rest of the parameters. The CREATE TABLE statement will have a
placeholder token of <table_name> in place of an actual table name.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ShowOwnSpid [<Switch>]
Retrieve data about the calling session?
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ShowSleepingSpids [<Int>]
Controls how sleeping SPIDs are handled, based on the idea of levels of interest
0 does not pull any sleeping SPIDs
1 pulls only those sleeping SPIDs that also have an open transaction
2 pulls all sleeping SPIDs
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ShowSystemSpids [<Switch>]
Retrieve data about system sessions?
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SortOrder [<String>]
Column(s) by which to sort output, optionally with sort directions.
Valid column choices:
session_id, physical_io, reads, physical_reads, writes, tempdb_allocations,
tempdb_current, CPU, context_switches, used_memory, physical_io_delta,
reads_delta, physical_reads_delta, writes_delta, tempdb_allocations_delta,
tempdb_current_delta, CPU_delta, context_switches_delta, used_memory_delta,
tasks, tran_start_time, open_tran_count, blocking_session_id, blocked_session_count,
percent_complete, host_name, login_name, database_name, start_time, login_time
Note that column names in the list must be bracket-delimited. Commas and/or white space are not required.
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. You must have sysadmin access and server version must be SQL
Server version 2000 or higher.
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: Community, WhoIsActive
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
http://whoisactive.com
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Invoke-DbaWhoIsActive -SqlInstance sqlserver2014a
Execute sp_whoisactive on sqlserver2014a. This command expects sp_WhoIsActive to be in the master database. Logs
into the SQL Server with Windows credentials.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Invoke-DbaWhoIsActive -SqlInstance sqlserver2014a -SqlCredential $credential -Database dbatools
Execute sp_whoisactive on sqlserver2014a. This command expects sp_WhoIsActive to be in the dbatools database. Logs
into the SQL Server with SQL Authentication.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Invoke-DbaWhoIsActive -SqlInstance sqlserver2014a -GetAverageTime
Similar to running sp_WhoIsActive @get_avg_time
-------------------------- EXAMPLE 4 --------------------------
PS C:\\>Invoke-DbaWhoIsActive -SqlInstance sqlserver2014a -GetOuterCommand -FindBlockLeaders
Similar to running sp_WhoIsActive @get_outer_command = 1, @find_block_leaders = 1
RELATED LINKS
https://dbatools.io/Invoke-DbaWhoIsActive