New CimSessionOption - PowerShell
Overview
New-CimSessionOption creates a new Common Information Model (CIM) session option object. This object can be used to specify the behavior of a CIM session.
Syntax
New-CimSessionOption [-Name] <string> [-ComputerName] <string> [-OperationTimeout] <uint16> [-Protocol] <CimProtocol> [-Namespace] <string> [-Filter] <string> [-Authentication] <CimAuthentication> [-Credential] <PSCredential> [-Port] <uint16> [-EnablePrivileges] <boolean> [-AsJob] [<CommonParameters>]
Options/Flags
| Option/Flag | Description | Default Value |
|—|—|—|
| -Name | The name of the session option. | NewCimSessionOption |
| -ComputerName | The name of the remote computer to connect to. | localhost |
| -OperationTimeout | The timeout for the session in seconds. | 120 |
| -Protocol | The CIM protocol to use. | DCOM |
| -Namespace | The CIM namespace to connect to. | root/cimv2 |
| -Filter | A filter to apply to the session. | None |
| -Authentication | The authentication mechanism to use. | Default |
| -Credential | The credential to use for authentication. | Current user credentials |
| -Port | The port number to use for the session. | 5985 |
| -EnablePrivileges | A flag indicating whether to enable privileges for the session. | False |
| -AsJob | A flag indicating whether to run the command as a job. | False |
Examples
Example 1: Creating a new CIM session option object
New-CimSessionOption -Name "MyCimSessionOption" -ComputerName "remotecomputer"
Example 2: Creating a new CIM session option object with a custom filter
New-CimSessionOption -Name "MyCimSessionOption" -ComputerName "remotecomputer" -Filter "SELECT * FROM Win32_Process WHERE Name LIKE '%powershell%'"
Common Issues
Issue: The command fails with an error message stating that the remote computer cannot be found.
Solution: Verify that the computer name is correct and that the computer is accessible from the local computer.
Issue: The command fails with an error message stating that the specified CIM namespace does not exist.
Solution: Verify that the namespace name is correct and that the namespace exists on the remote computer.
Integration
New-CimSessionOption can be used with the Invoke-CimMethod and Get-CimInstance cmdlets to perform CIM operations on remote computers.
Related Commands
- Invoke-CimMethod
- Get-CimInstance