Rename an item, in a PowerShell provider namespace.
Syntax
Rename-Item [-path] string[] [-newName] string [-force]
[-passThru] [-credential PSCredential] [-whatIf]
[-confirm] [CommonParameters]
Key
-path string
The path(s) to the item(s) to be renamed. Wildcards are permitted.
-newName string
The new name for the item.
-force
Override restrictions that prevent the command from succeeding, apart
from security settings. e.g. Force will create file path directories
or override a files read-only attribute, but will not change file permissions.
-passThru
Pass the object created by Rename-Item along the pipeline.
-credential PSCredential
Use a credential to validate access to the file. Credential represents
a user-name, such as "User01" or "Domain01\User01", or a PSCredential
object, such as the one retrieved by using the Get-Credential cmdlet.
If you type a user name, you will be prompted for a password.
This parameter is not supported by any PowerShell core cmdlets or providers.
-whatIf
Describe what would happen if you executed the command without
actually executing the command.
-confirm
Prompt for confirmation before executing the command.
CommonParameters:
-Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutVariable.
Examples
Rename a file:
PS C:\>rename-item -path c:\docs\dump.csv -newname Report.xls
Rename all .TXT files as .LOG files in the current directory:
PS C:\>get-childitem -Path *.txt | rename-item -NewName {$_.name -replace".txt",".log"}
Because the -Newname parameter does not accept wildcards, the above works by piping the output of Get-ChildItem and then using a -replace expression to calculate all the new filenames.
"It is the function of art to renew our perception. What we are familiar with we cease to see. The writer shakes up the familiar scene, and, as if by magic, we see a new meaning in it" - Anais Nin
Related:
clear-item - Remove content from a variable or an alias
Copy-Item - Copy an item from a namespace location
get-item - Return an object that represents an item in a namespace
invoke-item - Invoke an executable or open a file (START)
move-item - Move an item from one location to another
new-item ni Create a new item in a namespace
set-item - Set the value of a provider pathname
remove-item - Remove an item
StampMe - Script to rename a file with the current Date/Time
Equivalent bash command: mv - Move or rename files or directories