Get-PSBreakpoint

取得當前會話中設定的斷點。

語法

Line (預設值)

Get-PSBreakpoint
    [[-Script] <String[]>]
    [-Runspace <Runspace>]
    [<CommonParameters>]

Command

Get-PSBreakpoint
    [[-Script] <String[]>]
    -Command <String[]>
    [-Runspace <Runspace>]
    [<CommonParameters>]

Variable

Get-PSBreakpoint
    [[-Script] <String[]>]
    -Variable <String[]>
    [-Runspace <Runspace>]
    [<CommonParameters>]

Type

Get-PSBreakpoint
    [[-Script] <String[]>]
    [-Type] <BreakpointType[]>
    [-Runspace <Runspace>]
    [<CommonParameters>]

Id

Get-PSBreakpoint
    [-Id] <Int32[]>
    [-Runspace <Runspace>]
    [<CommonParameters>]

Description

指令 Get-PSBreakpoint 檔會取得當前會話設定的斷點。 你可以用 cmdlet 參數來取得特定的斷點。

斷點是指令或腳本中執行暫時停止的一個點,讓你能檢視指令內容。 Get-PSBreakpoint 是多個為除錯 PowerShell 腳本與指令而設計的 cmdlet 之一。 如需 PowerShell 調試程式的詳細資訊,請參閱 about_Debuggers。

範例

範例 1:取得所有腳本和函式的所有斷點

這個指令會讓目前工作階段中所有腳本和函式的所有斷點都被設定。

Get-PSBreakpoint

範例 2:依 ID 取得斷點

此指令會取得斷點 ID 為 2 的斷點。

Get-PSBreakpoint -Id 2
Function         :
IncrementAction  :
Enabled          :
TrueHitCount     : 0
Id               : 2
Script           : C:\ps-test\sample.ps1
ScriptName       : C:\ps-test\sample.ps1

範例 3:將 ID 管道傳送到 'Get-PSBreakpoint'

這些指令展示了如何透過將斷點 ID 輸入 Get-PSBreakpoint來取得斷點。

$B = `Set-PSBreakpoint` -Script "sample.ps1" -Command "Increment"
$B.Id | Get-PSBreakpoint

Set-PSBreakpoint這個 cmdlet 會在腳本的 Sample.ps1 Increment 函式上建立斷點,並將斷點物件儲存在變數中$B。 變數中$B斷點物件的 Id 屬性會被管道傳送到 Get-PSBreakpoint cmdlet 以顯示中斷點資訊。

範例 4:在指定腳本檔案中取得斷點

這個指令會取得 and SupportScript.ps1 檔案中Sample.ps1的所有斷點。

Get-PSBreakpoint -Script "Sample.ps1, SupportScript.ps1"

此指令不會取得其他可能在腳本或會話中函式中設定的中斷點。

範例 5:取得指定 cmdlet 中的斷點

此指令取得檔案中Sample.ps1所有設定為 的 Command Read-HostWrite-Host 斷點。

Get-PSBreakpoint -Command "Read-Host, Write-Host" -Script "Sample.ps1"

範例 6:在指定檔案中取得指令斷點

Get-PSBreakpoint -Type Command -Script "Sample.ps1"

此指令會取得 Sample.ps1 檔案中所有 Command 斷點。

範例 7:依變數取得斷點

此指令會取得在當前會話中 和 $Swap 變數上設定$Index的斷點。

Get-PSBreakpoint -Variable "Index, Swap"

範例 8:取得檔案中所有行斷點與變數斷點

這個指令會取得腳本中所有行斷點和變數斷點 Sample.ps1 。

Get-PSBreakpoint -Type Line, Variable -Script "Sample.ps1"

範例 9:將斷點設定在特定的執行空間中

在此範例中,工作啟動後,執行時設定中斷點為中斷 Set-PSBreakpoint 。 Runspace 會儲存在變數中,並使用 Get-PSBreakpoint 參數傳遞至 命令。 接著你可以檢查變數的 $breakpoint 斷點。

Start-Job -ScriptBlock {
    Set-PSBreakpoint -Command Start-Sleep
    Start-Sleep -Seconds 10
}

$runspace = Get-Runspace -Id 1

$breakpoint = Get-PSBreakpoint -Runspace $runspace

參數

-Command

指定一個指令斷點陣列,這些中斷點會設定在指定的指令名稱上。 輸入指令名稱,例如指令小程式或函式名稱。

參數屬性

類型:

String[]

預設值:None
支援萬用字元:False
不要顯示:False

參數集

Command
Position:Named
必要:True
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-Id

指定此指令小子所獲得的斷點 ID。 將 ID 輸入逗號分隔的清單。 你也可以將斷點 ID 管道接到 Get-PSBreakpoint。

參數屬性

類型:

Int32[]

預設值:None
支援萬用字元:False
不要顯示:False

參數集

Id
Position:0
必要:True
來自管線的值:True
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-Runspace

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

此參數已在PowerShell 7.2中新增。

參數屬性

類型:Runspace
預設值:None
支援萬用字元:False
不要顯示:False

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-Script

指定包含斷點的腳本陣列。 輸入路徑(可選)及一個或多個腳本檔案的名稱。 如果你省略路徑,預設位置就是目前的目錄。

參數屬性

類型:

String[]

預設值:None
支援萬用字元:False
不要顯示:False

參數集

Script
Position:Named
必要:False
來自管線的值:True
來自管線按屬性名稱的值:False
來自剩餘引數的值:False
Variable
Position:Named
必要:False
來自管線的值:True
來自管線按屬性名稱的值:False
來自剩餘引數的值:False
Command
Position:Named
必要:False
來自管線的值:True
來自管線按屬性名稱的值:False
來自剩餘引數的值:False
Type
Position:Named
必要:False
來自管線的值:True
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-Type

指定一個斷點類型陣列,該指令子會獲得這些類型。 這會是一種或多種類型。 此參數可接受的值為:

  • 線
  • Command
  • 變數

你也可以將斷點類型管道接到 Get-PSBreakpoint。

參數屬性

類型:

BreakpointType[]

預設值:None
接受的值:Line, Variable, Command
支援萬用字元:False
不要顯示:False

參數集

Type
Position:0
必要:True
來自管線的值:True
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-Variable

指定一個由指定變數名稱設置的變數斷點陣列。 輸入不加美元符號的變數名稱。

參數屬性

類型:

String[]

預設值:None
支援萬用字元:False
不要顯示:False

參數集

Variable
Position:Named
必要:True
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

CommonParameters

此 cmdlet 支援常見參數:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 如需詳細資訊,請參閱 about_CommonParameters。

輸入

Int32

你可以把斷點 ID 管道傳送到這個 cmdlet。

BreakpointType

你可以把斷點類型輸入這個指令碼。

輸出

CommandBreakpoint

LineBreakpoint

VariableBreakpoint

Breakpoint

此指令檔回傳代表會話中斷點的物件。

備註

PowerShell 包含下列 Get-PSBreakpoint的別名:

  • 所有平臺:
    • gbp