Get-SqlAgentJobStep

Gets a SQL JobStep object for each step that is present in the target instance of SQL Agent Job.

Syntax

Get-SqlAgentJobStep
   [[-Name] <String>]
   [[-Path] <String>]
   [<CommonParameters>]
Get-SqlAgentJobStep
   [[-Name] <String>]
   [-InputObject] <Job>
   [<CommonParameters>]

Description

The Get-SqlAgentJobStep cmdlet gets a SQL JobStep object for each step that is present in the target instance of SQL Agent Job. If you provide the name of the job step, the cmdlet gets only this specific JobStep object.

This cmdlet supports the following modes of operation to return a collection of JobStep objects:

  • Pass the instance of the SQL Agent Job in the input.
  • Specify the Path parameter of the Job instance.
  • Invoke the cmdlet in a valid context.

Examples

Example 1: Get all JobStep instances in the job instances

PS C:\> Get-SqlAgent -ServerInstance "MyServerInstance" | Get-SqlAgentJob | Get-SqlAgentJobStep

    Name      ID         OnSuccessAction           OnFailAction              LastRunDate               LastRunDuration 
    ----      --         ---------------           ------------              -----------               --------------- 
    step1     1          QuitWithSuccess           QuitWithFailure           1/1/0001 12:00:00 AM      4.03:23:45      
    step2     2          QuitWithSuccess           QuitWithFailure           1/1/0001 12:00:00 AM      00:33:59        
    step3     3          GoToNextStep              QuitWithSuccess           1/1/0001 12:00:00 AM      00:00:11

This command uses the Get-SqlAgent cmdlet to get the server instance named 'MyServerInstance' then passes the result using the pipeline to the Get-SqlAgentJob cmdlet. The command then passes the result using the pipeline to the Get-SqlAgentJobStep cmdlet to get all JobStep instances.

Example 2: Get a JobStep instance by name

PS C:\> Get-SqlAgent -ServerInstance "MyServerInstance" | Get-SqlAgentJob | Get-SqlAgentJobStep -Name "Step1"

    Name      ID         OnSuccessAction           OnFailAction              LastRunDate               LastRunDuration               
    ----      --         ---------------           ------------              -----------               ---------------               
    step1     1          QuitWithSuccess           QuitWithFailure           1/1/0001 12:00:00 AM      4.03:23:45

This command uses the Get-SqlAgent cmdlet to get the server instance named 'MyServerInstance' then passes the result using the pipeline to the Get-SqlAgentJob cmdlet. The command then passes the result using the pipeline to the Get-SqlAgentJobStep cmdlet to get the JobStep instance named 'Step1'.

Parameters

-InputObject

Specifies the job object of the target instance.

Type:Job
Position:2
Default value:None
Accept pipeline input:True (ByValue)
Accept wildcard characters:False
-Name

Specifies the name of the JobStep object that this cmdlet gets.

Type:String
Position:1
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Path

Specifies the path to the job object on which this cmdlet runs the operation. If you do not specify a value for this parameter, the cmdlet uses the current working location.

Type:String
Position:2
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

Inputs

Microsoft.SqlServer.Management.Smo.Agent.Job

Outputs

System.Object