Disable-PSBreakpoint
在目前的主控台中停用中斷點。
Syntax
Disable-PSBreakpoint
[-PassThru]
[-Breakpoint] <Breakpoint[]>
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Disable-PSBreakpoint
[-PassThru]
[-Id] <Int32[]>
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Description
Disable-PSBreakpoint Cmdlet 會停用斷點,以確保腳本執行時不會叫用這些斷點。 您可以使用它來停用所有中斷點,或是藉由送出中斷點物件或中斷點識別碼來指定中斷點。
就技術上來說,這個 Cmdlet 會將中斷點物件的 Enabled 屬性值變更為 False。 如果要重新啟用中斷點,請使用 Enable-PSBreakpoint Cmdlet。 使用 Set-PSBreakpoint Cmdlet 來建立中斷點時,中斷點預設會處於已啟用狀態。
中斷點是指令碼中的暫時停止執行點,用來讓您檢查指令碼中的指示。 Disable-PSBreakpoint 是專為偵錯 PowerShell 腳本而設計的數個 Cmdlet 之一。 如需PowerShell調試程式的詳細資訊,請參閱about_Debuggers。
範例
範例 1:設定斷點並加以停用
PS C:\> $B = Set-PSBreakpoint -Script "sample.ps1" -Variable "name"
PS C:\> $B | Disable-PSBreakpoint
這些命令會停用新建的中斷點。
第一個命令會使用 Set-PSBreakpoint Cmdlet,在 Sample.ps1 腳本的 Name 變數上建立斷點。 然後,它會將中斷點物件儲存在 $B 變數中。
第二個命令會使用 Disable-PSBreakpoint Cmdlet 來停用新的斷點。 它會使用管線運算子 (|) 將 $B 中的斷點對象傳送至 Disable-PSBreakpoint Cmdlet。
由於此命令,$B中斷點物件的 Enabled 屬性值為 False。
範例 2:停用斷點
PS C:\> Disable-PSBreakpoint -Id 0
此命令停用具有中斷點識別碼 0 的中斷點。
範例 3:Create 停用的斷點
PS C:\> Disable-PSBreakpoint -Breakpoint ($B = Set-PSBreakpoint -Script "sample.ps1" -Line 5)
PS C:\> $B
此命令建立新的中斷點,在您啟用之前它會是停用的。
它會使用 Disable-PSBreakpoint Cmdlet 來停用斷點。 斷點參數的值是 Set-PSBreakpoint 命令,可設定新的斷點、產生斷點物件,並將物件儲存在$B變數中。
以物件為其值的 Cmdlet 參數可接受包含物件的變數,或是取得或產生物件的命令。 在此情況下,因為 Set-PSBreakpoint 會產生斷點物件,所以它可以當做 斷點 參數的值使用。
第二個命令會在 $B 變數的值中顯示斷點物件。
範例 4:停用目前控制台中的所有斷點
PS C:\> Get-PSBreakpoint | Disable-PSBreakpoint
此命令停用目前主控台中的所有中斷點。 您可以將此命令縮寫為:"gbp | dbp"。
參數
-Breakpoint
指定要停用的中斷點。 請輸入包含中斷點物件的變數,或可取得中斷點物件的命令,例如 Get-PSBreakpoint 命令。 您也可以使用管線將斷點對象傳送至 Disable-PSBreakpoint Cmdlet。
Type: | Breakpoint[] |
Position: | 0 |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Confirm
在執行 Cmdlet 前提示您確認。
Type: | SwitchParameter |
Aliases: | cf |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Id
停用具有指定之中斷點識別碼的中斷點。 請輸入識別碼或包含識別碼的變數。 您無法使用管線將標識碼傳送至 Disable-PSBreakpoint。
Type: | Int32[] |
Position: | 0 |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-PassThru
傳回代表已啟用之中斷點的物件。 根據預設,此 Cmdlet 不會產生任何輸出。
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-WhatIf
顯示執行 Cmdlet 後會發生的情況。 Cmdlet 並不會執行。
Type: | SwitchParameter |
Aliases: | wi |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
輸入
您可以使用管線將斷點對象傳送至 Disable-PSBreakpoint。
輸出
None or System.Management.Automation.Breakpoint
當您使用 PassThru 參數時, Disable-PSBreakpoint 會傳回代表停用斷點的物件。 否則,此 Cmdlet 不會產生任何輸出。