Get CimSession - PowerShell


Overview

Get-CimSession retrieves information about the Windows Management Instrumentation (WMI) sessions established by the current user. These sessions are used to connect to remote or local computers and execute WMI commands.

Syntax

Get-CimSession [-ComputerName <String>] [-UseSsl] [-Authentication <WmiAuthentication>] [-Timeout <Int32>] [-ResourceUri <Uri>] [-Namespace <String>]

Options/Flags

  • -ComputerName: Specifies the computer where the WMI session is established.
  • -UseSsl: Establishes the WMI session using Secure Socket Layer (SSL).
  • -Authentication: Sets the authentication method for WMI sessions. Valid options are Basic, Kerberos, Credential, Negotiate, or Default.
  • -Timeout: Sets the time-out value in seconds for WMI operations.
  • -ResourceUri: Specifies the WMI resource URI to connect to.
  • -Namespace: Sets the WMI namespace to connect to.

Examples

Get all WMI sessions:

Get-CimSession

Get WMI sessions on a specific computer:

Get-CimSession -ComputerName remote-server

Establish a secure WMI session:

Get-CimSession -ComputerName remote-server -UseSsl

Connect to a specific WMI namespace:

Get-CimSession -ComputerName remote-server -Namespace root\cimv2

Common Issues

  • Ensure that WMI is enabled on the remote computer.
  • Verify that you have sufficient permissions to connect to the WMI namespace.
  • Adjust the -Timeout parameter if WMI operations are taking too long.

Integration

Get-CimSession can be combined with Invoke-WmiMethod to execute WMI commands on the specified computer:

$session = Get-CimSession -ComputerName remote-server
Invoke-WmiMethod -CimSession $session -Class Win32_OperatingSystem -Name GetVersion
  • New-CimSession: Creates a new WMI session.
  • Remove-CimSession: Removes an existing WMI session.
  • Invoke-WmiMethod: Executes WMI methods on remote computers.