Copy ItemProperty - PowerShell


Overview

Copy-ItemProperty copies property values from one item to another. This command is commonly used in automation scenarios to copy specific properties between items, such as file metadata, registry settings, or configuration parameters.

Syntax

Copy-ItemProperty [-Destination] <ItemDestination> -Source <ItemSource> [-Name] <String[]> [-Exclude] <String[]> [-Include] <String[]> [-PassThru] [-Force] [-Confirm] [-WhatIf] [<CommonParameters>]

Options/Flags

  • -Destination: Specifies the destination item to copy properties to.
  • -Source: Specifies the source item to copy properties from.
  • -Name: Specifies the names of the properties to copy.
  • -Exclude: Specifies a list of property names to exclude from copying.
  • -Include: Specifies a list of property names to include in copying.
  • -PassThru: Returns the destination item rather than the copied properties.
  • -Force: Overwrites existing property values on the destination item.
  • -Confirm: Prompts for confirmation before copying properties.
  • -WhatIf: Displays what actions would be performed without actually making any changes.

Examples

Simple copy:

Copy-ItemProperty -Source "C:\TestFile.txt" -Destination "C:\NewFile.txt"

Copy specific properties:

Copy-ItemProperty -Source $regPath -Destination $regVal -Name "value"

Exclude properties:

Copy-ItemProperty -Source $vm -Destination $newVm -Exclude "Name","Id"

Include properties:

Copy-ItemProperty -Source $site -Destination $newSite -Include "Title","Description"

PassThru:

$newSite = Copy-ItemProperty -Destination $newSite -Source $site -PassThru

Common Issues

  • Properties not copied: Ensure the -Name parameter is specified correctly and that the source item has the specified properties.
  • Access denied: Check permissions on both the source and destination items.
  • Property mismatch: The property value types may not match between the source and destination items.

Integration

  • Export-CSV: Copy properties to a CSV file for data analysis.
  • Select-Object: Filter properties before copying.
  • Set-ItemProperty: Modify or create properties on the destination item.
  • Get-ItemProperty: Retrieves item properties.
  • New-ItemProperty: Creates new properties on an item.
  • Remove-ItemProperty: Deletes properties from an item.