Edit

Share via


Debug-Job

Debugs a running background or remote job.

Syntax

JobParameterSet (Default)

Debug-Job
    [-Job] <Job>
    [-BreakAll]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

JobNameParameterSet

Debug-Job
    [-Name] <String>
    [-BreakAll]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

JobIdParameterSet

Debug-Job
    [-Id] <Int32>
    [-BreakAll]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

JobInstanceIdParameterSet

Debug-Job
    [-InstanceId] <Guid>
    [-BreakAll]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Description

The Debug-Job cmdlet lets you debug scripts that are running within jobs. The cmdlet is designed to debug PowerShell Workflow jobs, background jobs, and jobs running in remote sessions. Debug-Job accepts a running job object, name, ID, or instance ID as input, and starts a debugging session on the script it is running. The debugger quit command stops the job and running script. The exit command detaches the debugger, and allows the job to continue to run.

Examples

Example 1: Debug a job by job ID

This command breaks into a running job with an ID of 3.

Debug-Job -Id 3
Id     Name            PSJobTypeName   State         HasMoreData     Location             Command
--     ----            -------------   -----         -----------     --------             -------
3      Job3            RemoteJob       Running       True            PowerShellIx         TestWFDemo1.ps1
          Entering debug mode. Use h or ? for help.

          Hit Line breakpoint on 'C:\TestWFDemo1.ps1:8'

          At C:\TestWFDemo1.ps1:8 char:5
          +     Write-Output -InputObject "Now writing output:"
          +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          [DBG:PowerShellIx]: PS C:\> > list

              3:
              4:  workflow SampleWorkflowTest
              5:  {
              6:      param ($MyOutput)
              7:
              8:*     Write-Output -InputObject "Now writing output:"
              9:      Write-Output -Input $MyOutput
             10:
             11:      Write-Output -InputObject "Get PowerShell process:"
             12:      Get-Process -Name powershell
             13:
             14:      Write-Output -InputObject "Workflow function complete."
             15:  }
             16:
             17:  # Call workflow function
             18:  SampleWorkflowTest -MyOutput "Hello"

Parameters

-BreakAll

Allows you to break immediately in the current location when the debugger attaches.

This parameter was added in PowerShell 7.2.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Parameter properties

Type:SwitchParameter
Default value:False
Supports wildcards:False
DontShow:False
Aliases:cf

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Id

Specifies the ID number of a running job. To get the ID number of a job, run the Get-Job cmdlet.

Parameter properties

Type:Int32
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

JobIdParameterSet
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-InstanceId

Specifies the instance ID GUID of a running job.

Parameter properties

Type:Guid
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

JobInstanceIdParameterSet
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Job

Specifies a running job object. The simplest way to use this parameter is to save the results of a Get-Job command that returns the running job that you want to debug in a variable, and then specify the variable as the value of this parameter.

Parameter properties

Type:Job
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

JobParameterSet
Position:0
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:True
Value from remaining arguments:False

-Name

Specifies a job by the friendly name of the job. When you start a job, you can specify a job name by adding the JobName parameter, in cmdlets such as Invoke-Command and Start-Job.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

JobNameParameterSet
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Parameter properties

Type:SwitchParameter
Default value:False
Supports wildcards:False
DontShow:False
Aliases:wi

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Inputs

System.Management.Automation.RemotingJob