Get-Cim
Session
Syntax
Get-CimSession
[[-ComputerName] <String[]>]
[<CommonParameters>]
Get-CimSession
[-Id] <UInt32[]>
[<CommonParameters>]
Get-CimSession
-InstanceId <Guid[]>
[<CommonParameters>]
Get-CimSession
-Name <String[]>
[<CommonParameters>]
Description
The Get-CimSession cmdlet gets the CIM session objects created in the current PowerShell session.
If used without any parameters, the cmdlet gets all of the CIM sessions created in the current PowerShell session.
You can use the parameters of
Get-CimSession
to get the sessions that are for particular computers, or you can identify sessions by their names, IDs, or instance IDs.
For more information about PowerShell sessions, see about_CimSession .
Examples
Example 1: Get CIM sessions from the current PowerShell session
By default,
Get-CimSession
only gets information about the CIM sessions that exist in the current PowerShell session.
Get-CimSession does not get CIM sessions that were created in other PowerShell sessions or that were created on other computers.
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
This command first creates CIM sessions by using
New-CimSession
, and then gets the CIM sessions by using
Get-CimSession
.
Example 2: Get the CIM sessions to a specific computer
Get-CimSession -ComputerName Server02
Id : 2
Name : CimSession2
InstanceId : c0095981-52c5-4e7f-a5bb-c4c680541710
ComputerName : Server02
Protocol : WSMAN
This command gets the CIM sessions that are connected to the computer named Server02.
Example 3: Get a list of CIM sessions and then format the list
Get-CimSession | Format-Table -Property ComputerName,InstanceId
ComputerName InstanceId
------------ ----------
Server01 d1413bc3-162a-4cb8-9aec-4d2c61253d59
Server02 c0095981-52c5-4e7f-a5bb-c4c680541710
This command gets all of the CIM sessions in the current PowerShell session, and then formats the list in a table containing only the ComputerName and InstanceID properties.
Example 4: Get all the CIM sessions that have specific names
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
This command gets all of the CIM sessions that have names that begin with the characters serv.
Example 5: Get a specific CIM session
Get-CimSession -ID 2
Id : 2
Name : CimSession2
InstanceId : c0095981-52c5-4e7f-a5bb-c4c680541710
ComputerName : Server02
Protocol : WSMAN
This command gets the CIM session that has an ID of 2.
Required Parameters
Specifies the identifier (ID) of the CIM session to get. For one or more IDs, use commas to separate the IDs, or use the range operator (..) to specify a range of IDs.
An ID is an integer that uniquely identifies the CIM session in the current PowerShell session. It is easier to remember and type than InstanceId, but it is unique only within the current PowerShell session.
For more information about the range operator, see about_Operators .
Type: | UInt32[] |
Position: | 1 |
Default value: | None |
Accept pipeline input: | True (ByPropertyName) |
Accept wildcard characters: | False |
Specifies the instance IDs of the CIM session to get.
InstanceId is a GUID that uniquely identifies a CIM session. The InstanceId is unique, even when you have multiple sessions running in PowerShell.
The InstanceId is stored in the InstanceId property of the object that represents a CIM session.
Type: | Guid[] |
Position: | Named |
Default value: | None |
Accept pipeline input: | True (ByPropertyName) |
Accept wildcard characters: | False |
Gets one or more CIM sessions which contain the specified friendly names. Wildcard characters are permitted.
Type: | String[] |
Position: | Named |
Default value: | None |
Accept pipeline input: | True (ByPropertyName) |
Accept wildcard characters: | True |
Optional Parameters
Specifies an array of names of computers. Gets the CIM sessions that connect to the specified computers.
You can specify a fully qualified domain name (FQDN) or a NetBIOS name.
Type: | String[] |
Aliases: | CN, ServerName |
Position: | 1 |
Default value: | None |
Accept pipeline input: | True (ByPropertyName) |
Accept wildcard characters: | True |
Inputs
None
Outputs
Microsoft.Management.Infrastructure.CimSession