The Debug-Job cmdlet lets you debug scripts that are running within jobs.
The cmdlet is designed to debug Windows 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.
Starting in Windows PowerShell 5.0, the exit command detaches the debugger, and allows the job to continue to run.
示例
Example 1: Debug a job by job ID
PS C:\> 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"
This command breaks into a running job with an ID of 3.
参数
-Confirm
Prompts you for confirmation before running the cmdlet.
参数属性
类型:
SwitchParameter
默认值:
False
支持通配符:
False
不显示:
False
别名:
cf
参数集
(All)
Position:
Named
必需:
False
来自管道的值:
False
来自管道的值(按属性名称):
False
来自剩余参数的值:
False
-Id
Specifies the ID number of a running job.
To get the ID number of a job, run the Get-Job cmdlet.
参数属性
类型:
Int32
默认值:
None
支持通配符:
False
不显示:
False
参数集
JobIdParameterSet
Position:
0
必需:
True
来自管道的值:
False
来自管道的值(按属性名称):
False
来自剩余参数的值:
False
-InstanceId
Specifies the instance ID GUID of a running job.
To get the InstanceId of a job, run the Get-Job cmdlet, piping the results into a Format-* cmdlet, as shown in the following example:
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.
参数属性
类型:
Job
默认值:
None
支持通配符:
False
不显示:
False
参数集
JobParameterSet
Position:
0
必需:
True
来自管道的值:
True
来自管道的值(按属性名称):
True
来自剩余参数的值:
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.
参数属性
类型:
String
默认值:
None
支持通配符:
False
不显示:
False
参数集
JobNameParameterSet
Position:
0
必需:
True
来自管道的值:
False
来自管道的值(按属性名称):
False
来自剩余参数的值:
False
-WhatIf
Shows what would happen if the cmdlet runs.
The cmdlet is not run.
参数属性
类型:
SwitchParameter
默认值:
False
支持通配符:
False
不显示:
False
别名:
wi
参数集
(All)
Position:
Named
必需:
False
来自管道的值:
False
来自管道的值(按属性名称):
False
来自剩余参数的值:
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.