Share via


Remove-CimSession

Removes one or more CIM sessions.

Syntax

CimSessionSet (Default)

Remove-CimSession
    [-CimSession] <CimSession[]>
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

ComputerNameSet

Remove-CimSession
    [-ComputerName] <String[]>
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

SessionIdSet

Remove-CimSession
    [-Id] <UInt32[]>
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

InstanceIdSet

Remove-CimSession
    -InstanceId <Guid[]>
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

NameSet

Remove-CimSession
    -Name <String[]>
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Description

The Remove-CimSession cmdlet removes one or more CIM session objects from the local PowerShell session.

Examples

Example 1: Remove all the CIM sessions

Get-CimSession | Remove-CimSession

This command retrieves all the available CIM sessions on the local computer using the Get-CimSession cmdlet, and then removes them using the Remove-CimSession.

Example 2: Remove a specific CIM session

Remove-CimSession -Id 5

This command removes the CIM session that has an ID value of 5.

Example 3: Show the list of CIM sessions to remove by using the WhatIf parameter

Remove-CimSession -Name a* -WhatIf

This command uses the common parameter WhatIf to specify that the removal should not be done, but only output what would happen if it were done.

Parameters

-CimSession

Specifies the session objects of the CIM sessions to close.

Enter a variable that contains the CIM session, or a command that creates or gets the CIM session, such as the New-CimSession or Get-CimSession cmdlets. For more information, see about_CimSessions.

Parameter properties

Type:

CimSession[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

CimSessionSet
Position:0
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:True
Value from remaining arguments:False

-ComputerName

Specifies the name of the computer to get CIM sessions connected to. Wildcard characters are permitted.

Parameter properties

Type:

String[]

Default value:None
Supports wildcards:True
DontShow:False
Aliases:CN, ServerName

Parameter sets

ComputerNameSet
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Parameter properties

Type:SwitchParameter
Default value:False
Supports wildcards:False
DontShow:False
Aliases:cf

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Id

Specifies the ID of the CIM session to remove. Specify one or more IDs separated by commas, 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.

Parameter properties

Type:

UInt32[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

SessionIdSet
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-InstanceId

Specifies the instance ID of the CIM session to remove.

InstanceId is a Globally Unique Identifier (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.

Parameter properties

Type:

Guid[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

InstanceIdSet
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-Name

Specifies the friendly name of the CIM session to remove. You can use wildcard characters with this parameter.

Parameter properties

Type:

String[]

Default value:None
Supports wildcards:True
DontShow:False

Parameter sets

NameSet
Position:Named
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:True
Value from remaining arguments:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Parameter properties

Type:SwitchParameter
Default value:False
Supports wildcards:False
DontShow:False
Aliases:wi

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Inputs

None

This cmdlet accepts no input objects.

Outputs

Object

This cmdlet returns an object that contains CIM session information.