Get-PSBreakpoint
取得目前工作階段中設定的中斷點。
Syntax
Get-PSBreakpoint
[[-Script] <String[]>]
[-Runspace <Runspace>]
[<CommonParameters>]
Get-PSBreakpoint
[[-Script] <String[]>]
-Command <String[]>
[-Runspace <Runspace>]
[<CommonParameters>]
Get-PSBreakpoint
[[-Script] <String[]>]
-Variable <String[]>
[-Runspace <Runspace>]
[<CommonParameters>]
Get-PSBreakpoint
[[-Script] <String[]>]
[-Type] <BreakpointType[]>
[-Runspace <Runspace>]
[<CommonParameters>]
Get-PSBreakpoint
[-Id] <Int32[]>
[-Runspace <Runspace>]
[<CommonParameters>]
Description
Cmdlet Get-PSBreakPoint
會取得在目前會話中設定的斷點。 您可以使用 Cmdlet 參數以取得特定的中斷點。
中斷點是命令或指令碼中的暫時停止執行點,用來讓您檢查指示。 Get-PSBreakpoint
是數個專為偵錯 PowerShell 腳本和命令而設計的 Cmdlet 之一。 如需 PowerShell 調試程式的詳細資訊,請參閱 about_Debuggers。
範例
範例 1:取得所有腳本和函式的所有斷點
此命令會取得在目前工作階段中之所有指令碼和函式上設定的所有中斷點。
Get-PSBreakpoint
範例 2:依標識碼取得斷點
此命令會取得具有中斷點識別碼 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:使用管線將標識符傳送至 'Get-PSBreakpoint'
這些命令示範如何將斷點標識碼管線傳送至 Get-PSBreakpoint
,以取得斷點。
$B = `Set-PSBreakpoint` -Script "sample.ps1" -Command "Increment"
$B.Id | Get-PSBreakpoint
Cmdlet 會在 Set-PSBreakpoint
腳本中的 Increment Sample.ps1
函式上建立斷點,並將斷點物件儲存在 變數中 $B
。 變數中$B
斷點物件的Id屬性會透過管道傳送至 Get-PSBreakpoint
Cmdlet 以顯示斷點資訊。
範例 4:在指定的腳本檔案中取得斷點
此命令會取得和 SupportScript.ps1
檔案中的所有Sample.ps1
斷點。
Get-PSBreakpoint -Script "Sample.ps1, SupportScript.ps1"
此命令不會取得其他斷點,這些斷點可能設定於其他腳本或會話中的函式上。
範例 5:取得指定 Cmdlet 中的斷點
此命令會取得在 或 Write-Host
檔案中Sample.ps1
設定Read-Host
的所有命令斷點。
Get-PSBreakpoint -Command "Read-Host, Write-Host" -Script "Sample.ps1"
範例 6:取得指定檔案中的命令斷點
Get-PSBreakpoint -Type Command -Script "Sample.ps1"
此命令會取得 Sample.ps1 檔案中的所有命令中斷點。
範例 7:依變數取得斷點
此命令會取得在目前會話的 $Index
和 $Swap
變數上設定的斷點。
Get-PSBreakpoint -Variable "Index, Swap"
範例 8:取得檔案中的所有行和變數斷點
此命令會取得腳本中的所有 Sample.ps1
行和變數斷點。
Get-PSBreakpoint -Type Line, Variable -Script "Sample.ps1"
範例 9:取得在特定 Runspace 中設定的斷點
在此範例中,會啟動作業,並將中斷點設定為在執行 Set-PSBreakPoint
時中斷。 Runspace 會儲存在變數中,而且會使用 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
指定在指定命令名稱上設定的命令斷點陣列。 輸入命令名稱,例如 Cmdlet 或函式的名稱。
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Id
指定這個 Cmdlet 取得的斷點標識碼。 以逗號分隔的清單方式輸入識別碼。 您也可以使用管線將斷點識別碼傳送至 Get-PSBreakpoint
。
Type: | Int32[] |
Position: | 0 |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Runspace
指定 Runspace 物件的識別碼,讓您可以在指定的 Runspace 中與斷點互動。
此參數已新增至 PowerShell 7.2。
Type: | Runspace |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Script
指定包含斷點的文稿陣列。 輸入路徑 (選擇性) 和一或多個腳本檔案的名稱。 若省略路徑,則預設位置為目前目錄。
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Type
指定這個 Cmdlet 取得的斷點類型數位。 輸入一個或多個類型。 此參數可接受的值為:
- 折線圖
- 命令
- 變數
您也可以使用管線將斷點類型傳送至 Get-PSBreakPoint
。
Type: | BreakpointType[] |
Accepted values: | Line, Variable, Command |
Position: | 0 |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Variable
指定在指定變數名稱上設定的變數斷點陣列。 輸入不含貨幣符號的變數名稱。
Type: | String[] |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
輸入
您可以使用管線將斷點標識碼傳送至此 Cmdlet。
您可以使用管線將斷點類型傳送至此 Cmdlet。
輸出
此 Cmdlet 會傳回物件,代表會話中的斷點。
備註
PowerShell 包含的下列別名 Get-PSBreakpoint
:
- 所有平台:
gbp