New-CIMInstance (PowerShell 3.0+ )

Create an instance of a CIM class based on the class definition on either the local computer or a remote computer. The Common Information Model (CIM) is the DMTF standard [DSP0004] for describing the structure and behavior of managed resources such as storage, network, or software components.

    New-CimInstance [ -ComputerName String[] | -CimSession  CimSession[] ] [-ClassName] String
       [-Key String[]] [-ClientOnly] [-Namespace String] [-OperationTimeoutSec UInt32]
          [[-Property] IDictionary] [-Confirm] [-WhatIf] [CommonParameters]

    New-CimInstance [ -ComputerName String[]] | -CimSession CimSession[] ] -ResourceUri Uri
       [-Key String[]] [-Namespace String] [-OperationTimeoutSec UInt32]
          [-Property] IDictionary] [-Confirm] [-WhatIf] [CommonParameters]

    New-CimInstance [ -ComputerName String[]] | -CimSession CimSession[] ] [-CimClass] CimClass
       [-ClientOnly]  [-OperationTimeoutSec UInt32]
          [[-Property] IDictionary] [-Confirm] [-WhatIf] [CommonParameters]
   -CimClass CimClass
       Specifies a CIM class object that represents the type of the instance.
       You can use the Get-CimClass cmdlet to retrieve the class declaration from a computer.
       Using this parameter results in better client side schema validations.

   -CimSession CimSession[]
       The CIM session to use for this cmdlet. 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.
   -ClassName String
       The name of the CIM class for which to retrieve the CIM instances. 
       NOTE: You can use tab completion to browse the list of classes, because wps_2 gets a list of classes from the 
       local WMI server to provide a list of class names.

       Indicates that the instance is only created in wps_1 without going to the CIM server. You can use this 
       parameter to create an in-memory CIM instance for use in subsequent wps_2 operations.

   -ComputerName String[]
       The computer on which you want to run the CIM operation. You can specify a fully qualified domain name 
       (FQDN), a NetBIOS name, or an IP address.
       If you specify this parameter, the cmdlet creates a temporary session to the specified computer using the 
       WsMan protocol.If you do not specify this parameter, the cmdlet performs the operation on the local computer
       using Component Object Model (COM).

       If multiple operations are being performed on the same computer, using a CIM session gives better performance.
   -Key String
       Specifies the properties that are used as keys. -CimSession and -ComputerName cannot be used when -Key is specified.
   -Namespace String
       Specifies the namespace of the class for the new instance.
       The default namespace is root/cimv2. 
       NOTE: You can use tab completion to browse the list of namespaces, because wps_2 gets a list of namespaces 
       from the local WMI server to provide the list of namespaces.
   -OperationTimeoutSec UInt32
       Specifies the amount of time that the cmdlet waits for a response from the computer.
       By default, the value of this parameter is 0, which means that the cmdlet uses the default timeout value for 
       the server.
       If the OperationTimeoutSec parameter is set to a value less than the robust connection retry timeout of 3 
       minutes, network failures that last more than the value of the OperationTimeoutSec parameter are not 
       recoverable, because the operation on the server times out before the client can reconnect.
   -Property IDictionary
       Specifies the properties of the CIM instance using a hash table (name-value pairs).
       If you specify the CimClass parameter, then the New-CimInstance cmdlet performs a property validation on the 
       client to make sure that the properties specified are consistent with the class declaration on the server. If 
       the CimClass parameter is not specified, then the property validation is done on the server.
   -ResourceUri Uri
       Specifies the resource uniform resource identifier (URI) of the resource class or instance. The URI is used to 
       identify a specific type of resource, such as disks or processes, on a computer.
       A URI consists of a prefix and a path to a resource. For example: 
       By default, if you do not specify this parameter, the DMTF standard resource URI is used and the class name is appended to it.
       ResourceURI can only be used with CIM sessions created using the WSMan protocol, or when specifying the 
       ComputerName parameter, which creates a CIM session using WSMan. If you specify this parameter without 
       specifying the ComputerName parameter, or if you specify a CIM session created using DCOM protocol, you will 
       get an error, because the DCOM protocol does not support the ResourceURI parameter.
       If both the -ResourceUri parameter and the -Filter parameter are specified, the -Filter parameter is ignored.

       Prompt for confirmation before executing the command.

       Describe the command without actually executing it.

       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable,
       -OutBuffer, PipelineVariable -OutVariable.

Use the Property parameter to set the initial values of the selected properties. By default, the New-CimInstance cmdlet creates an instance on the local computer.

Standard Aliases for New-CIMInstance: ncim

CIM Classes

The CIM classes available will vary according to your operating system.
List all CIM classes:
PS C:\> Get-cimclass

List all the classes involding discs:
PS C:\> Get-cimclass -List | Where cimClassName -like "*disk*"

Some common CIM classes:

 Win32_Baseboard    (Motherboard)
 Win32_LogicalDisk  (hard disk)
 Win32_OperatingSystem  (Virtual Memory)
 Win32_Processor    (32+64 bit processor info)
 Win32_Product      (avoid this: see Q974524)
 Win32_Share        (File shares)

List all properties of a class:
PS C:\> Get-CIMinstance Win32_BIOS | Get-Member

Find a specific class property:

PS C:\> gcim Win32_bios | Get-Member -MemberType property | Where { $ -match 'install'}
or simply:
PS C:\> gcim Win32_bios | Get-Member -MemberType property | Where name -match 'install'


Create an instance of a CIM Class named win32_environment in the root/cimv2 namespace on the computer.:

PS C:\> New-CimInstance -ClassName Win32_Environment -Property @{Name="testvar";VariableValue="testvalue";UserName="domain\user"}

Retrieve a CIM class object and store it in a variable named $class

PS C:\> $class = Get-CimClass -ClassName Win32_Environment

Pass the contents of the variable to the New-CimInstance cmdlet:

PS C:\> New-CimInstance -CimClass $class -Property @{Name="testvar";VariableValue="testvalue";UserName="ss64dom\User64"}

Creates a dynamic instance of the CIM class win32_Process on the client computer without getting the instance from the server. Store the dynamic instance in a variable named $dyn:

PS C:\> $dyn = New-CimInstance -ClassName Win32_Process -Property @{Handle=0} -Key Handle -ClientOnly

Pass the contents of the $dyn variable to Get-CimInstance:

PS C:\> Get-CimInstance –CimInstance $dyn

Invoke the GetOwner method against this dynamic instance:

PS C:\> Invoke-CimMethod -CimInstance $dyn -MethodName GetOwner

Get an instance of a CIM class named MSFT_Something in the namespace root/ss64 and stores it in a variable named $class

PS C:\> $class = Get-CimClass -ClassName MSFT_Something -Namespace root/ss64

Create a new CIM instance and perform client side validations on the new instance:

PS C:\> New-CimInstance -CimClass $class -Property @{"Prop1"=1;"Prop2"="value"} -ClientOnly

If you want to validate the instance, for example, to make sure Prop1 and Prop2 actually exist and that the keys are marked correctly, use the CimClass parameter instead of the ClassName parameter.

“There is no instance of a nation benefitting from prolonged warfare” ~ Sun Tzu

Related PowerShell Commands:

Get-CIMInstance - Get a managed resource (storage, network, software etc)
Get-Credential - Get a security credential object based on a user name and password.
RUNDLL32 - Run a DLL command (add/remove print connections)

Copyright © 1999-2019
Some rights reserved