New CimInstance - PowerShell


Overview

The New-CimInstance command creates a new instance of a CIM (Common Information Model) class. CIM classes represent managed objects such as files, services, and system components. This command enables you to create new objects in WMI (Windows Management Instrumentation), which is a framework for managing and monitoring Windows systems.

Syntax

New-CimInstance [-ClassName] <string> [-NamespaceName] <string> [-Property] <PSCimInstanceProperty> [-CimSession] <CimSession> [-EnableAllPrivileges] [-Authentication] <string> [-ImpersonationLevel] <string>

Options/Flags

| Option | Description | Default |
|—|—|—|
| -ClassName | Specifies the name of the CIM class for which to create an instance. | Required |
| -NamespaceName | Specifies the namespace in which to create the instance. | Required |
| -Property | Specifies the properties to set for the new instance. | Optional |
| -CimSession | Specifies the CIM session to use. | Current session |
| -EnableAllPrivileges | Specifies whether to enable all privileges. | False |
| -Authentication | Specifies the authentication mechanism to use. | Default |
| -ImpersonationLevel | Specifies the impersonation level to use. | Default |

Examples

Example 1: Create a new instance of the Win32_Process class

New-CimInstance -ClassName Win32_Process -NamespaceName root\cimv2 -Property@{Name="powershell.exe"; CommandLine="""C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe""" -NoLogo"}

Example 2: Create a new instance of the Win32_Service class and set multiple properties

New-CimInstance -ClassName Win32_Service -NamespaceName root\cimv2 -Property@{Name="MyService"; DisplayName="My Service"; StartMode="Automatic"}

Common Issues

  • Ensure that the CIM class and namespace exist before creating an instance.
  • Use the Get-CimClass and Get-CimNamespace commands to verify the existence of the class and namespace.
  • Specify the required properties for the CIM class. Use the Get-CimClass command to retrieve the required properties for the class.

Integration

  • Use New-CimInstance together with Invoke-CimMethod to perform operations on the created instance.
  • Combine New-CimInstance with Get-CimInstance and Remove-CimInstance for advanced object management.
  • Get-CimInstance
  • Invoke-CimMethod
  • Remove-CimInstance