共用方式為


Enable-PSBreakpoint

啟用目前控制台中的斷點。

語法

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

Description

Enable-PSBreakpoint Cmdlet 會重新啟用已停用的斷點。 您可以使用它來啟用所有斷點,或藉由提供斷點對象或標識碼來啟用特定斷點。

斷點是腳本中的一個點,執行會暫時停止,讓您可以檢查腳本的狀態。 新建立的斷點會自動啟用,但可以使用 Disable-PSBreakpoint停用。

從技術上看,此 Cmdlet 會將斷點物件的 Enabled 屬性值變更為 true

Enable-PSBreakpoint 是數個專為偵錯 PowerShell 腳本而設計的 Cmdlet 之一。 如需 PowerShell 調試程式的詳細資訊,請參閱 about_Debuggers

範例

範例 1:啟用所有斷點

這個範例會啟用目前會話中的所有斷點。

Get-PSBreakpoint | Enable-PSBreakpoint

使用別名時,此範例可以縮寫為 gbp | ebp

範例 2:依標識符啟用斷點

此範例會使用斷點標識碼來啟用多個斷點。

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 腳本的 Name 變數上建立斷點,並將斷點物件儲存在 $B 變數中。 PassThru 參數會顯示斷點 Enabled 屬性的值 False

Enable-PSBreakpoint 重新啟用斷點。 同樣地,使用 PassThru 參數,我們看到 enabled 屬性 的值是 True

範例 4:使用變數啟用斷點

這個範例會使用斷點對象來啟用一組斷點。

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

Get-PSBreakpoint 取得斷點,並將其儲存在 $B 變數中。 使用 斷點 參數,Enable-PSBreakpoint 啟用斷點。

這個範例相當於執行 Enable-PSBreakpoint -Id 3, 5

範例 5:在 Runspace 中啟用斷點

在此範例中,以斷點啟動作業會設定為中斷,然後停用。 Runspace 會儲存在變數中,並使用 Runspace 參數傳遞至 Get-PSBreakPoint 命令。 Get-PSBreakPoint 的輸出會管線傳送至 Enable-PSBreakpoint,以啟用 Runspace 中的斷點。

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

指定要啟用之斷點的 識別碼 編號。 預設值為所有斷點。 依數位或變數提供 識別碼。 您無法使用管線將 識別碼 數位傳送至 Enable-PSBreakpoint。 若要尋找斷點的 標識子,請使用 Get-PSBreakpoint Cmdlet。

類型:Int32[]
Position:0
預設值:None
必要:True
接受管線輸入:True
接受萬用字元:False

-PassThru

傳回 物件,表示正在啟用的斷點。 根據預設,此 Cmdlet 不會產生任何輸出。

類型:SwitchParameter
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-Runspace

指定 Runspace 物件的 識別符,讓您可以在指定的 Runspace 中與斷點互動。

此參數已在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 建立斷點時,就會啟用斷點。 您不需要啟用新建立的斷點。