Get-Runspace

取得 PowerShell 主機進程內的作用中 Runspace。

Syntax

Get-Runspace
   [[-Name] <String[]>]
   [<CommonParameters>]
Get-Runspace
   [-Id] <Int32[]>
   [<CommonParameters>]
Get-Runspace
   [-InstanceId] <Guid[]>
   [<CommonParameters>]

Description

Cmdlet 會在 Get-Runspace PowerShell 主機進程中取得作用中的 Runspace。

範例

範例 1:取得 Runspaces

Get-Runspace

Id Name            ComputerName    Type          State         Availability
 -- ----            ------------    ----          -----         ------------
  1 Runspace1       localhost       Local         Opened        Busy
  2 Runspace2       localhost       Local         Opened        Available
  3 Runspace3       localhost       Local         Opened        Available

範例 2:依標識符取得 Runspace

Get-Runspace -Id 2

Id Name            ComputerName    Type          State         Availability
 -- ----            ------------    ----          -----         ------------
  2 Runspace2       localhost       Local         Opened        Available

範例 3:依名稱取得 Runspace

Get-Runspace -Name Runspace1

Id Name            ComputerName    Type          State         Availability
 -- ----            ------------    ----          -----         ------------
  1 Runspace1       localhost       Local         Opened        Busy

範例 4:依 InstanceId 取得 Runspace

在這裡範例中,我們會使用 Name 參數識別可用的 Runspace,並將傳回物件儲存至變數 $activeRunspace。 這可讓您在後續的執行Get-Runspace中使用 Runspace 的屬性

$activeRunspace = Get-Runspace -Name Runspace1
Get-Runspace -InstanceId $activeRunspace.InstanceId

Id Name            ComputerName    Type          State         Availability
 -- ----            ------------    ----          -----         ------------
  1 Runspace1       localhost       Local         Opened        Busy

參數

-Id

指定 Runspace 的識別碼

Type:Int32[]
Position:0
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-InstanceId

指定執行中作業的實例識別碼 GUID。

Type:Guid[]
Position:0
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-Name

指定 Runspace 的名稱

Type:String[]
Position:0
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

輸出

Runspace

此 Cmdlet 會傳 回 Runspace。 您可以使用管線將命令的結果 Get-Runspace 傳送至 Debug-Runspace