Exploring Move-ItemProperty in PowerShell
Welcome back to Wahmans PowerShell blog! Today, we’re diving into a somewhat lesser-known but useful cmdlet: Move-ItemProperty. According to Microsoft’s documentation, this cmdlet “Moves a property from one location to another.” In this blog post, we’ll look at what that means and how you can leverage this cmdlet in your scripting. We’ll also go through four examples ranging from simple to advanced use cases. Let’s get started!
What is Move-ItemProperty?
The Move-ItemProperty cmdlet allows you to transfer a property from one item to another. It is most commonly used in the Windows Registry but can potentially be used in other PowerShell providers that support it.
Examples of Move-ItemProperty
1. Basic Usage – Move a Registry Property
Let’s move a registry value named TestValue from one key to another:
Move-ItemProperty -Path 'HKCU:\Software\DemoSource' -Name 'TestValue' -Destination 'HKCU:\Software\DemoDestination'
This command takes the TestValue from the DemoSource registry key and moves it to the DemoDestination key.
2. Use with Dynamic Path Variables
You can use variables to make the cmdlet even more flexible:
$source = 'HKCU:\Software\MyApp\SettingsA'
$destination = 'HKCU:\Software\MyApp\SettingsB'
$propertyName = 'ConfigOption'
Move-ItemProperty -Path $source -Name $propertyName -Destination $destination
This is helpful for scripts that need to process multiple keys or properties dynamically.
3. Conditional Movement Based on Property Existence
Want to ensure a value exists before moving it? Combine with Test-Path:
$source = 'HKCU:\Software\Utilities\Config1'
$destination = 'HKCU:\Software\Utilities\Config2'
$property = 'EnableFeatureX'
if (Test-Path "$source\$property") {
Move-ItemProperty -Path $source -Name $property -Destination $destination
} else {
Write-Output "Property $property does not exist at $source"
}
This avoids errors when a property is missing.
4. Advanced Scenario – Batch Move Multiple Properties
Let’s say you have multiple properties that need to be moved between registry keys. Here’s how to do that in a loop:
$sourceKey = 'HKLM:\Software\Company\OldSettings'
$destinationKey = 'HKLM:\Software\Company\NewSettings'
$propertiesToMove = @('Setting1', 'Setting2', 'Setting3')
foreach ($prop in $propertiesToMove) {
if (Test-Path "$sourceKey\$prop") {
Move-ItemProperty -Path $sourceKey -Name $prop -Destination $destinationKey
Write-Output "Moved $prop to $destinationKey"
} else {
Write-Output "$prop does not exist in $sourceKey"
}
}
This approach is great for configuration migrations or legacy key clean-up scripts.
Conclusion
Move-ItemProperty might not be the first cmdlet you reach for, but it can be a powerful tool in your scripting toolbox when organizing or migrating properties between registry keys or other supported providers.
Happy scripting, and I will see you in the next post!
Leave a Reply