Get-DbaAgentJobStep
View SourceSynopsis
Retrieves detailed SQL Agent job step information including execution status and configuration from SQL Server instances.
Description
Collects comprehensive details about SQL Agent job steps across one or more SQL Server instances. Returns information about each step’s subsystem type, last execution date, outcome, and current state, which is essential for monitoring job performance and troubleshooting failed automation tasks. You can filter results by specific jobs, exclude disabled jobs, or process job objects from Get-DbaAgentJob to focus on particular maintenance routines or scheduled processes.
Syntax
Get-DbaAgentJobStep
[[-SqlInstance] <DbaInstanceParameter[]>]
[[-SqlCredential] <PSCredential>]
[[-Job] <String[]>]
[[-ExcludeJob] <String[]>]
[[-InputObject] <Job[]>]
[-ExcludeDisabledJobs]
[-EnableException]
[<CommonParameters>]
Examples
Example: 1
PS C:\> Get-DbaAgentJobStep -SqlInstance localhost
Returns all SQL Agent Job Steps on the local default SQL Server instance
Example: 2
PS C:\> Get-DbaAgentJobStep -SqlInstance localhost, sql2016
Returns all SQL Agent Job Steps for the local and sql2016 SQL Server instances
Example: 3
PS C:\> Get-DbaAgentJobStep -SqlInstance localhost -Job BackupData, BackupDiff
Returns all SQL Agent Job Steps for the jobs named BackupData and BackupDiff from the local SQL Server instance.
Example: 4
PS C:\> Get-DbaAgentJobStep -SqlInstance localhost -ExcludeJob BackupDiff
Returns all SQL Agent Job Steps for the local SQL Server instances, except for the BackupDiff Job.
Example: 5
PS C:\> Get-DbaAgentJobStep -SqlInstance localhost -ExcludeDisabledJobs
Returns all SQL Agent Job Steps for the local SQL Server instances, excluding the disabled jobs.
Example: 6
PS C:\> $servers | Get-DbaAgentJobStep
Find all of your Job Steps from SQL Server instances in the $servers collection
Optional Parameters
-SqlInstance
The target SQL Server instance or instances. This can be a collection and receive pipeline input to allow the function to be executed against multiple SQL Server instances.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | true (ByValue) |
| Default Value |
-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.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| Default Value |
-Job
Specifies which SQL Agent jobs to include by name when retrieving job steps. Accepts wildcards for pattern matching.
Use this when you need to examine steps for specific jobs like backup routines or maintenance tasks instead of processing all jobs on the instance.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| Default Value |
-ExcludeJob
Specifies which SQL Agent jobs to exclude by name when retrieving job steps. Accepts wildcards for pattern matching.
Use this when you want to review most jobs but skip certain ones like test jobs or jobs that generate excessive output.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| Default Value |
-InputObject
Accepts SQL Agent job objects from the pipeline, typically from Get-DbaAgentJob output.
Use this when you want to process job steps for a pre-filtered set of jobs or when building complex pipelines that combine job filtering with step analysis.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | true (ByValue) |
| Default Value |
-ExcludeDisabledJobs
Filters out disabled SQL Agent jobs from the results, showing only currently active jobs.
Use this when troubleshooting production issues or monitoring active automation to avoid reviewing steps from jobs that aren’t currently running.
| Property | Value |
|---|---|
| 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.
| Property | Value |
|---|---|
| Alias | |
| Required | False |
| Pipeline | false |
| Default Value | False |
Outputs
Microsoft.SqlServer.Management.Smo.Agent.JobStep
Returns one SQL Agent Job Step object per step within each specified job. Each object represents a discrete step within a SQL Server Agent job with its configuration and execution details.
Default display properties (via Select-DefaultView):
- ComputerName: The name of the SQL Server computer where the step is located
- InstanceName: The name of the SQL Server instance
- SqlInstance: The full SQL Server instance name (computer\instance)
- AgentJob: The name of the parent SQL Agent job containing this step
- Name: The name of the job step
- SubSystem: The subsystem type for the step (TransactSql, PowerShell, CmdExec, AnalysisCommand, AnalysisQuery, Ssis, etc.)
- LastRunDate: DateTime of the last execution of this step
- LastRunOutcome: Outcome of the last execution (Succeeded, Failed, Retry, Cancelled, Unknown, etc.)
- State: Current state of the step (Enabled, Disabled, etc.)
*Additional properties available from the SMO JobStep object (accessible via Select-Object ):
- ID: Internal step ID number
- CreateDate: DateTime when the step was created
- DateLastModified: DateTime when the step was last modified
- Command: The command or script to execute for this step
- CommandExecutionSuccessCode: Exit code indicating success (0 for success by default)
- DatabaseName: Database context for the step execution
- DatabaseUserName: User context for step execution
- Description: Step description/notes
- IncludeStepOutput: Boolean indicating if step output is included in job history
- IsLastStep: Boolean indicating if this is the last step in the job
- LogToTable: Boolean indicating if output is logged to a table
- OutputFileName: File path for step output logging
- ProxyID: ID of the proxy account used for this step
- RetryAttempts: Number of retry attempts if the step fails
- RetryInterval: Interval in minutes between retry attempts Note: The ComputerName, InstanceName, SqlInstance, and AgentJob properties are added by the function and are not native SMO properties.
dbatools