Share via


How to create a new instance

This topic shows how to create a new instance using the CreateInstance intrinsic method.

[!Important]
This example uses the Win32_Environment class, defined in the root\cimv2 namespace, because it implements the CreateInstance method.

 

New-EnvironmentVariable -Name <string> -UserName <string> -VariableValue <string> 

The following sample CDXML shows how to markup a CDXML file to use the CreateInstance method to create a new instance of an object.

<PowerShellMetadata xmlns="https://schemas.microsoft.com/cmdlets-over-objects/2009/11">
  <Class ClassName="ROOT\cimv2\Win32_Environment">
    <Version>1.0.0.0</Version>
    <DefaultNoun>EnvironmentVariable</DefaultNoun>
    <StaticCmdlets>
      <Cmdlet>
        <CmdletMetadata Verb="New"/>
        <Method MethodName="cim:CreateInstance">
          <Parameters>
            <Parameter ParameterName="Name">
              <Type PSType="System.String"/>
              <CmdletParameterMetadata IsMandatory="true"/>
            </Parameter>
            <Parameter ParameterName="UserName">
              <Type PSType="System.String"/>
              <CmdletParameterMetadata IsMandatory="true"/>
            </Parameter>
            <Parameter ParameterName="VariableValue">
              <Type PSType="System.String"/>
              <CmdletParameterMetadata IsMandatory="true"/>
            </Parameter>
          </Parameters>
        </Method>
      </Cmdlet>
    </StaticCmdlets>
  </Class>
</PowerShellMetadata>