PowerShell Genie

New-CimSession

Use New-CimSession to create a reusable CIM session to a remote computer for use with the CIM cmdlets.

Command 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn — PowerShell module reference

Syntax

1PS> New-CimSession [[-ComputerName] <string[]>] [-Credential <PSCredential>] [-Authentication <PasswordAuthenticationMechanism>] [-Name <String>] [-Port <UInt32>] [-SessionOption <CimSessionOptions>] [-OperationTimeoutSec <UInt32>] [<CommonParameters>]
See the command anatomy

Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

New-CimSession [[-ComputerName] <string[]>] [-Credential <PSCredential>] [-Authentication <PasswordAuthenticationMechanism>] [-Name <String>] [-Port <UInt32>] [-SessionOption <CimSessionOptions>] [-OperationTimeoutSec <UInt32>] [<CommonParameters>]
  1. Stage 1New-CimSession-ComputerName -Credential -Authentication -Name -Port -SessionOption -OperationTimeoutSec

    Try it

    Windows PowerShell

    PowerShell example · browser support is limited.

    Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.

    Interactive simulation · fictional data

    Examples

    New-CimSession -ComputerName SRV01;

    1PS> $c = New-CimSession -ComputerName SRV01; Get-CimInstance Win32_Service -CimSession $c
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Id  Name         ComputerName  Protocol
    --  ----         ------------  --------
    1   CimSession1  SRV01         WSMAN

    New-CimSession -Protocol DCOM;

    1PS> $o = New-CimSessionOption -Protocol DCOM; New-CimSession -ComputerName OLD01 -SessionOption $o
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Id  Name         ComputerName  Protocol
    --  ----         ------------  --------
    1   CimSession1  SRV01         WSMAN

    Get-CimInstance -ClassName Win32_OperatingSystem

    1PS> Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object Caption, Version
    Show reference output

    Sample output · fictional data, shaped like the real thing

    Caption  Version
    -------  -------
    Microsoft Windows 11 Pro  10.0.26100

    Parameters

    Parameter definitions:

    • -ComputerName
    • -Credential
    • -Authentication
    • -Name
    • -Port
    • -SessionOption
    • -OperationTimeoutSec

    PowerShell module reference on Microsoft Learn

    Practical use and troubleshooting

    Practical scenario: Use New-CimSession when you need to create a reusable CIM session to a remote computer for use with the CIM cmdlets. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.

    Common error and fix: A connection failure can come from protocol or endpoint configuration. Confirm whether the target supports WSMan or requires a deliberately configured DCOM option; check credentials and firewall policy. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.

    See also: Get-CimInstance. Get-CimInstance queries instances; New-CimSession creates a reusable connection description for later CIM calls. A session object is not a hardware inventory result. Read the linked command before substituting it; similar names do not imply identical inputs or output.

    New-CimSession reference on Microsoft Learn

    Recap

    New-CimSession Use New-CimSession to create a reusable CIM session to a remote computer for use with the CIM cmdlets.

    Next: New-PSSession
    Genie guideNew-CimSession

    Use New-CimSession to create a reusable CIM session to a remote computer for use with the CIM cmdlets. The console below is pre-loaded — run it, then change a value and run it again.