Move ItemProperty - PowerShell


Overview

The Move-ItemProperty cmdlet moves a property from one item to another. This can be useful for reorganizing properties or moving them to a more appropriate location.

Syntax

Move-ItemProperty [-Source] <PSObject> [-Destination] <PSObject> [-Name] <String[]> [-PassThru] [-ErrorAction <ActionPreference>] [-ErrorVariable <String>] [-OutVariable <String>] [-OutBuffer <Int32>] [-Verbose] [-Debug] [-Confirm] [-WhatIf] [-Force]

Options/Flags

  • -Source: Specifies the source PSObject from which the property will be moved.
  • -Destination: Specifies the destination PSObject to which the property will be moved.
  • -Name: Specifies the name of the property to be moved.
  • -PassThru: Returns the destination PSObject after the property has been moved.
  • -ErrorAction: Specifies the action to be taken if an error occurs.
  • -ErrorVariable: Specifies the variable in which to store the error message if an error occurs.
  • -OutVariable: Specifies the variable in which to store the output of the command.
  • -OutBuffer: Specifies the number of objects to be buffered in memory before they are written to the output stream.
  • -Verbose: Writes verbose information to the console.
  • -Debug: Writes debugging information to the console.
  • -Confirm: Prompts the user to confirm the operation before executing it.
  • -WhatIf: Shows what would happen if the command were executed without actually executing it.
  • -Force: Suppresses the confirmation prompt when the command is executed.

Examples

Single-Property Move

Move-ItemProperty -Source $sourcePSObject -Destination $destinationPSObject -Name "Property1"

Multiple-Property Move

Move-ItemProperty -Source $sourcePSObject -Destination $destinationPSObject -Name "Property1", "Property2", "Property3"

Using PassThru

$result = Move-ItemProperty -Source $sourcePSObject -Destination $destinationPSObject -Name "Property1" -PassThru

Common Issues

One common issue that users may encounter is that the property to be moved does not exist in the source PSObject. In this case, the cmdlet will throw an error. To avoid this, use the -WhatIf parameter to see what would happen if the command were executed without actually executing it.

Integration

The Move-ItemProperty cmdlet can be combined with other PowerShell commands to perform more complex tasks. For example, the following command moves all properties from the $sourcePSObject to the $destinationPSObject:

Get-ItemProperty -Path $sourcePSObject | Move-ItemProperty -Destination $destinationPSObject
  • Get-ItemProperty
  • Set-ItemProperty