New ItemProperty - PowerShell


Overview

New-ItemProperty creates a new property on a given item. This is useful for adding custom properties to objects in PowerShell, such as adding metadata to files or folders.

Syntax

New-ItemProperty -Path <string> -Name <string> -Value <object>

Required Parameters:

  • -Path: The path to the item to which the property will be added.
  • -Name: The name of the property to be created.
  • -Value: The value to be assigned to the property.

Optional Parameters:

  • -Confirm: Prompts you for confirmation before executing the command.
  • -ErrorAction: Specifies the action to take if an error occurs.
  • -Force: Overwrites an existing property with the same name.
  • -Namespace: Specifies the namespace for the property.
  • -Type: Specifies the type of the property.

Options/Flags

None.

Examples

Create a new property on a file:

New-ItemProperty -Path "C:\path\to\file.txt" -Name "Owner" -Value "John Doe"

Create a new property on a folder:

New-ItemProperty -Path "C:\path\to\folder" -Name "Description" -Value "This folder contains important documents."

Create a new property with a specified namespace and type:

New-ItemProperty -Path "C:\path\to\file.txt" -Name "CustomProperty" -Value "Value" -Namespace "Custom" -Type [string]

Common Issues

  • Error: Property already exists: If you try to create a property with the same name as an existing property, you will receive an error. Use the -Force parameter to overwrite the existing property.
  • Error: Invalid value: The value you specify for the property must be valid for the specified type. For example, if you specify a string value for a property of type [int], you will receive an error.

Integration

New-ItemProperty can be used in conjunction with other PowerShell commands to automate tasks. For example, you can use the Get-Item command to retrieve an item and then use New-ItemProperty to add a new property to it.

  • Get-ItemProperty
  • Remove-ItemProperty
  • Set-ItemProperty