Rename ItemProperty - PowerShell
Overview
Rename-ItemProperty is a PowerShell command used to rename properties of objects in the file system or in a collection of objects. This command allows you to modify the names of properties associated with files, directories, or objects in PowerShell sessions.
Syntax
Rename-ItemProperty [-Path] <string[]> [-Name] <string[]> [-NewName] <string[]> [-Force] [-Confirm] [-WhatIf] [-PassThru] [-ErrorAction <Action>] [-ErrorVariable <string>] [-OutVariable <string>]
Options/Flags
-Path: Specifies the path to the item(s) whose property you want to rename. Accepts wildcards.
-Name: The current name of the property you want to rename.
-NewName: The new name you want to assign to the property.
-Force: Overwrites existing properties with the same name without prompting for confirmation.
-Confirm: Prompts for confirmation before executing the command.
-WhatIf: Performs a simulation of the command without actually changing anything.
-PassThru: Returns the modified object(s) with the renamed property.
-ErrorAction: Specifies the action to take when an error occurs.
-ErrorVariable: Assigns errors to a specified variable.
-OutVariable: Assigns the output to a specified variable.
Examples
Simple Rename:
Rename-ItemProperty -Path "C:\Users\John\Documents\File.txt" -Name "LastWriteTime" -NewName "ModifiedTime"
Bulk Rename:
Get-ChildItem "C:\Users\John\Documents" | Rename-ItemProperty -Name "DateCreated" -NewName "CreationDate"
Common Issues
- Property Not Found: Ensure the specified property name exists and is valid for the object type.
- Overwrite Conflict: Use the -Force parameter to overwrite existing properties with the same name.
Integration
With Get-ChildItem: Get the properties of files and rename them in a loop:
Get-ChildItem "C:\Users\John\Documents" | ForEach-Object { Rename-ItemProperty -Path $_.FullName -Name "DateCreated" -NewName "CreationDate" }
Related Commands
- New-ItemProperty: Creates new properties.
- Get-ItemProperty: Gets the value of properties.
- Remove-ItemProperty: Removes properties.