Powershell

How to Use the New-ItemProperty Cmdlet to Create a New Item’s Property in PowerShell?

The “New-ItemProperty” cmdlet is utilized to create a new property for an item in PowerShell. Moreover, it also sets its value at a specified location. Specifically, it is used to create new registry values of the registry keys. However, this cmdlet does not add properties to an object. This cmdlet does not have any aliases.

This tutorial will elaborate on the usage of PowerShell’s “New-ItemProperty” cmdlet.

How to Use the New-ItemProperty Cmdlet to Create a New Item’s Property in PowerShell?

To create a new item in PowerShell, first, use the “New-ItemProperty” cmdlet. Then specify the property’s path using the “-Path” parameter. After that, use the “-Name” parameter and specify the name for the property. Lastly, mention the value to be assigned to the property by using the “-Value” parameter.

Let’s have an overview of the given examples to understand the usage of the stated cmdlet.

Example 1: Use the “New-ItemProperty” Cmdlet to Add a Registry Entry

Execute the given command to add a new registry entry by utilizing the cmdlet “New-ItemProperty”:

New-ItemProperty -Path "HKLM:\Software\NewSoftware" -Name "Users" -Value 76

According to the above code:

  • First, use the “New-ItemProperty” cmdlet.
  • Then, add the “-Path” parameter and specify the stated path.
  • After that, use the “-Name” parameter and mention the item name followed by the “-Value” parameter having the stated value assigned to it:

Example 2: Use the “New-ItemProperty” Cmdlet to Add a New Registry Entry to a Key

To add a new registry entry to a key, run the cmdlet “New-ItemProperty”:

Get-Item -Path "HKLM:\Software\NewSoftware" | New-ItemProperty -Name NoOfDevelopers -Value 6

Here:

  • Initially, use the “Get-Item” cmdlet and assign it the provided path using the “-Path” parameter.
  • Then, pipe the provided command to the “New-ItemProperty” cmdlet followed by the “-Name” parameter having the stated value assigned.
  • Lastly, add the “-Value” parameter to assign a specified value:

Example 3: Use the “New-ItemProperty” Cmdlet to Create Multi String Values

In order to create multi-string values simply execute the given command:

$newVal = New-ItemProperty -Path "HKLM:\SOFTWARE\NewCompany" -Name "SampleString" -PropertyType MultiString -Value ("One","Two","Three")

According to the above command:

  • First, initialize a variable “$newVal” and specify the “New-ItemProperty” cmdlet along with the parameter “-Path” the provided path mentioned to it.
  • Then, use the parameter “-Name” and specify the name of the property.
  • Next, utilize the “-PropertyType” parameter and assign the value “MultiString” to it.
  • Lastly, use the “-Value” parameter and provide multiple string values separated by commas enclosed within parentheses:

That’s it! We have illustrated the usage of the “New-ItemProperty” cmdlet in PowerShell.

Conclusion

The “New-ItemProperty” cmdlet is utilized to create a new property for an item in PowerShell. It creates registry values for the registry keys. Moreover, it does not have any aliases in PowerShell. This tutorial elaborated on the usage of PowerShell’s “New-ItemProperty” cmdlet.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.