共用方式為


Get-CimSession

從目前的工作階段取得 CIM 工作階段物件。

語法

ComputerNameSet (預設值)

Get-CimSession
    [[-ComputerName] <String[]>]
    [<CommonParameters>]

SessionIdSet

Get-CimSession
    [-Id] <UInt32[]>
    [<CommonParameters>]

InstanceIdSet

Get-CimSession
    -InstanceId <Guid[]>
    [<CommonParameters>]

NameSet

Get-CimSession
    -Name <String[]>
    [<CommonParameters>]

Description

此 Cmdlet 只能在 Windows 平臺上使用。

根據預設,Cmdlet 會取得在目前 PowerShell 工作階段中建立的所有 CIM 作業階段。 您可以使用 Get-CimSession 的參數來取得特定計算機的會話,也可以依其名稱或其他標識碼來識別會話。 Get-CimSession 無法取得在其他 PowerShell 工作階段中建立的 CIM 會話或在其他電腦上建立的 CIM 會話。

如需 CIM 會話的詳細資訊,請參閱 about_CimSession

範例

範例 1:從目前的 PowerShell 會話取得 CIM 會話

此範例會先使用 New-CimSession建立 CIM 會話,然後再使用 Get-CimSession取得 CIM 會話。

New-CimSession -ComputerName Server01, Server02
Get-CimSession
Id           : 1
Name         : CimSession1
InstanceId   : d1413bc3-162a-4cb8-9aec-4d2c61253d59
ComputerName : Server01
Protocol     : WSMAN

Id           : 2
Name         : CimSession2
InstanceId   : c0095981-52c5-4e7f-a5bb-c4c680541710
ComputerName : Server02
Protocol     : WSMAN

範例 2:取得特定計算機的 CIM 會話

此範例可取得連線到名為 Server02的電腦之 CIM 會話。

Get-CimSession -ComputerName Server02
Id           : 2
Name         : CimSession2
InstanceId   : c0095981-52c5-4e7f-a5bb-c4c680541710
ComputerName : Server02
Protocol     : WSMAN

範例 3:取得 CIM 會話的清單,然後格式化清單

此範例會取得目前 PowerShell 工作階段中的所有 CIM 工作階段,並顯示只包含 ComputerNameInstanceId 屬性的數據表。

Get-CimSession | Format-Table -Property ComputerName, InstanceId
ComputerName InstanceId
------------ ----------
Server01     d1413bc3-162a-4cb8-9aec-4d2c61253d59
Server02     c0095981-52c5-4e7f-a5bb-c4c680541710

範例 4:取得具有特定名稱的所有 CIM 工作階段

此範例會取得名稱開頭為 Serv的所有 CIM 工作階段。

Get-CimSession -ComputerName Serv*
Id           : 1
Name         : CimSession1
InstanceId   : d1413bc-162a-4cb8-9aec-4d2c61253d59
ComputerName : Server01
Protocol     : WSMAN

Id           : 2
Name         : CimSession2
InstanceId   : c0095981-52c5-4e7f-a5bb-c4c680541710
ComputerName : Server02
Protocol     : WSMAN

範例 5:取得特定的 CIM 會話

此範例會取得具有 2 識別碼 的 CIM 會話。

Get-CimSession -Id 2
Id           : 2
Name         : CimSession2
InstanceId   : c0095981-52c5-4e7f-a5bb-c4c680541710
ComputerName : Server02
Protocol     : WSMAN

參數

-ComputerName

指定要連接 CIM 工作階段的目標電腦名稱。 允許使用通配符字元。

參數屬性

類型:

String[]

預設值:None
支援萬用字元:True
不要顯示:False
別名:中國, 伺服器名稱

參數集

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

-Id

指定要取得之 CIM 會話的識別碼。 針對多個標識碼,請使用逗號分隔標識符,或使用範圍運算符 (..) 來指定標識符的範圍。 識別碼 是整數,可唯一識別目前PowerShell會話內的 CIM 會話。

如需範圍運算子的詳細資訊,請參閱 about_Operators

參數屬性

類型:

UInt32[]

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

參數集

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

-InstanceId

指定要取得之 CIM 會話的實例識別碼。

InstanceId 是可唯一識別 CIM 會話的全域唯一標識碼 (GUID)。 InstanceId 是唯一的,即使在 PowerShell 中執行多個會話時也是如此。

InstanceId 會儲存在代表 CIM 會話之物件的 InstanceId 屬性中。

參數屬性

類型:

Guid[]

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

參數集

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

-Name

取得包含指定易記名稱的一或多個 CIM 會話。 允許使用通配符字元。

參數屬性

類型:

String[]

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

參數集

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

CommonParameters

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

輸入

None

您不能將物件透過管道傳送到此 Cmdlet。

輸出

CimSession

此 Cmdlet 會傳回 CIM 會話物件。

備註

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

  • 窗戶:
    • gcms

此 Cmdlet 僅適用於 Windows 平臺。