Enable-PSBreakpoint

启用当前控制台中的断点。

语法

Enable-PSBreakpoint
      [-PassThru]
      [-Breakpoint] <Breakpoint[]>
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]
Enable-PSBreakpoint
      [-PassThru]
      [-Id] <Int32[]>
      [-Runspace <Runspace>]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]

说明

Enable-PSBreakpoint cmdlet 重新启用禁用断点。 可以通过提供断点对象或 ID 来启用所有断点或特定断点。

断点是脚本中的一个点,其中执行会暂时停止,以便检查脚本的状态。 新创建的断点会自动启用,但可以使用 Disable-PSBreakpoint禁用。

从技术上看,此 cmdlet 将断点对象的 Enabled 属性的值更改为 True

Enable-PSBreakpoint 是用于调试 PowerShell 脚本的多个 cmdlet 之一。 有关 PowerShell 调试器的详细信息,请参阅 about_Debuggers

示例

示例 1:启用所有断点

此示例启用当前会话中的所有断点。

Get-PSBreakpoint | Enable-PSBreakpoint

使用别名时,此示例可以缩写为 gbp | ebp

示例 2:按 ID 启用断点

此示例使用断点 ID 启用多个断点。

Enable-PSBreakpoint -Id 0, 1, 5

示例 3:启用禁用的断点

此示例重新启用已禁用的断点。

$B = Set-PSBreakpoint -Script "sample.ps1" -Variable Name -PassThru
$B | Enable-PSBreakpoint -PassThru

AccessMode : Write
Variable   : Name
Action     :
Enabled    : False
HitCount   : 0
Id         : 0
Script     : C:\ps-test\sample.ps1
ScriptName : C:\ps-test\sample.ps1

AccessMode : Write
Variable   : Name
Action     :
Enabled    : True
HitCount   : 0
Id         : 0
Script     : C:\ps-test\sample.ps1
ScriptName : C:\ps-test\sample.ps1

Set-PSBreakpoint 脚本的 Sample.ps1 变量上创建断点,将断点对象保存在 $B 变量中。 PassThru 参数显示断点 Enabled 属性的值 False

Enable-PSBreakpoint 重新启用断点。 同样,使用 PassThru 参数,我们看到已启用 属性的值 True

示例 4:使用变量启用断点

此示例使用断点对象启用一组断点。

$B = Get-PSBreakpoint -Id 3, 5
Enable-PSBreakpoint -Breakpoint $B

Get-PSBreakpoint 获取断点并将其保存在 $B 变量中。 使用 断点 参数,Enable-PSBreakpoint 启用断点。

此示例等效于运行 Enable-PSBreakpoint -Id 3, 5

示例 5:在运行空间中启用断点

在此示例中,作业从断点开始,设置为中断,然后禁用。 runspace 存储在变量中,并使用 Get-PSBreakpoint 参数传递给 命令。 Get-PSBreakpoint 的输出通过管道传递给 Enable-PSBreakpoint,以便在运行空间中启用断点。

Start-Job -ScriptBlock {
    $bp = Set-PSBreakpoint -Command Start-Sleep
    Disable-PSBreakpoint $bp
    Start-Sleep -Seconds 10
}

$runspace = Get-Runspace -Id 1

Get-PSBreakpoint -Runspace $runspace | Enable-Breakpoint -Runspace $runspace

参数

-Breakpoint

指定要启用的断点。 提供包含断点的变量或获取断点对象的命令,例如 Get-PSBreakpoint。 还可以通过管道将断点对象传递给 Enable-PSBreakpoint

类型:Breakpoint[]
Position:0
默认值:None
必需:True
接受管道输入:True
接受通配符:False

-Confirm

在运行 cmdlet 之前,提示你进行确认。

类型:SwitchParameter
别名:cf
Position:Named
默认值:False
必需:False
接受管道输入:False
接受通配符:False

-Id

指定要启用的断点的 ID 数字。 默认值为所有断点。 按数字或变量提供 ID。 无法通过管道 ID 数字 Enable-PSBreakpoint。 若要查找断点的 ID,请使用 Get-PSBreakpoint cmdlet。

类型:Int32[]
Position:0
默认值:None
必需:True
接受管道输入:True
接受通配符:False

-PassThru

返回一个对象,该对象表示正在启用的断点。 默认情况下,此 cmdlet 不会生成任何输出。

类型:SwitchParameter
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-Runspace

指定 Runspace 对象的 ID,以便你可以与指定运行空间中的断点进行交互。

此参数已在 PowerShell 7.2 中添加。

类型:Runspace
别名:RunspaceId
Position:Named
默认值:None
必需:False
接受管道输入:True
接受通配符:False

-WhatIf

显示 cmdlet 运行时会发生什么情况。 该 cmdlet 未运行。

类型:SwitchParameter
别名:wi
Position:Named
默认值:False
必需:False
接受管道输入:False
接受通配符:False

输入

Breakpoint

可以通过管道将断点对象传递给此 cmdlet。

输出

None

默认情况下,此 cmdlet 不返回任何输出。

Breakpoint

使用 PassThru 参数时,此 cmdlet 返回表示已启用断点的断点对象。

备注

PowerShell 包含以下 Enable-PSBreakpoint别名:

  • 所有平台:

    • ebp
  • 如果尝试启用已启用断点,Enable-PSBreakpoint cmdlet 不会生成错误。 因此,即使只有少数断点被禁用,也可以启用所有断点而不出错。

  • 使用 Set-PSBreakpoint cmdlet 创建断点时会启用断点。 无需启用新创建的断点。