PowerShell Logo Small

New-CimInstance



This is the built-in help made by Microsoft for the command 'New-CimInstance', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Creates a CIM instance.

SYNTAX


New-CimInstance [-ClassName] <String> [[-Property] <IDictionary>] [-ClientOnly] [-ComputerName <String[]>] [-Key <String[]>] [-Namespace <String>] [-OperationTimeoutSec
<UInt32>] [-Confirm] [-WhatIf] [<CommonParameters>]
New-CimInstance [-CimClass] <CimClass> [[-Property] <IDictionary>] [-ClientOnly] [-ComputerName <String[]>] [-OperationTimeoutSec <UInt32>] [-Confirm] [-WhatIf]
[<CommonParameters>]
New-CimInstance [-CimClass] <CimClass> [[-Property] <IDictionary>] [-ClientOnly] [-OperationTimeoutSec <UInt32>] -CimSession <CimSession[]> [-Confirm] [-WhatIf]
[<CommonParameters>]
New-CimInstance [-ClassName] <String> [[-Property] <IDictionary>] [-ClientOnly] [-Key <String[]>] [-Namespace <String>] [-OperationTimeoutSec <UInt32>] -CimSession
<CimSession[]> [-Confirm] [-WhatIf] [<CommonParameters>]
New-CimInstance [[-Property] <IDictionary>] [-Key <String[]>] [-Namespace <String>] [-OperationTimeoutSec <UInt32>] -CimSession <CimSession[]> -ResourceUri <Uri> [-Confirm]
[-WhatIf] [<CommonParameters>]
New-CimInstance [[-Property] <IDictionary>] [-ComputerName <String[]>] [-Key <String[]>] [-Namespace <String>] [-OperationTimeoutSec <UInt32>] -ResourceUri <Uri> [-Confirm]
[-WhatIf] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The New-CimInstance cmdlet creates an instance of a CIM class based on the class definition on either the local computer or a remote computer.


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.



<

RELATED LINKS

Get-CimClass
Get-CimInstance
Remove-CimInstance
Set-CimInstance

REMARKS

<

Examples


Example 1: Create an instance of a CIM class

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



This command creates an instance of a CIM Class named win32_environment in the root/cimv2 namespace on the computer.

No client side validation is performed if the class does not exist, the properties are wrong, or if the server rejects the call.

If the instance is created successfully, then the New-CimInstance cmdlet outputs the newly created instance.






Example 2: Create an instance of a CIM class using a class schema

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



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



This set of commands retrieves a CIM class object and stores it in a variable named $class using the Get-CimClass cmdlet. The contents of the variable are then passed to the
New-CimInstance cmdlet.






Example 3: Create a dynamic instance on the client

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


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


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



This set of commands creates a dynamic instance of a CIM class named win32_Process on the client computer without getting the instance from the server. This set of commands
retrieves the dynamic instance and stores it in a variable named $a and passes the contents of the variable to the Get-CimInstance cmdlet. The Get-CimInstance cmdlet then
retrieves a particular single instance, and invokes the GetOwner method using the Invoke-CimMethod cmdlet.

This dynamic instance can be used to perform operations if the instance with this key exists on the server.






Example 4: Create an instance for a CIM class of a specific namespace

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



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



This set of commands gets an instance of a CIM class named MSFT_Something in the namespace root/somewhere and stores it in a variable named $class using the Get-CimClass
cmdlet. The contents of the variable are then passed to the New-CimInstance cmdlet to create a new CIM instance and perform client side validations on the new instance.

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.

You cannot use the ComputerName or CimSession parameter with the ClientOnly parameter.