CmdID

CmdID / PowerShell / Cmdlets / Rename

Rename-Item

Renames an item in a PowerShell provider namespace. PowerShell reference

From the PowerShell reference 9 parameters Aliases ren, rni

Opens CmdID with your command, read as PowerShell. It is read in your browser and sent nowhere.

What it does

from the PowerShell reference, CC BY 4.0

Renames an item in a PowerShell provider namespace. The Rename-Item cmdlet changes the name of a specified item. This cmdlet does not affect the content of the item being renamed. You can't use Rename-Item to move an item, such as by specifying a path together with the new name. To move and rename an item, use the Move-Item cmdlet. You can't use Rename-Item to replace an existing item, such as renaming log_new.txt to log_current.txt when log_current.txt already exists. To replace an existing item, use the Move-Item cmdlet with the Force parameter.

Rename-Item [-Path] <String> [-NewName] <String> [-Force] [-PassThru] [-Credential <PSCredential>] [-WhatIf] [-Confirm] [-UseTransaction] [<CommonParameters>]
Rename-Item -LiteralPath <String> [-NewName] <String> [-Force] [-PassThru] [-Credential <PSCredential>] [-WhatIf] [-Confirm] [-UseTransaction] [<CommonParameters>]

Rename a file

Rename-Item -Path "C:\logfiles\daily_file.txt" -NewName "monday_file.txt"Identify

Rename and move an item

Rename-Item -Path "project.txt" -NewName "D:\archive\old-project.txt"Identify

Rename a registry key

Rename-Item -Path "HKLM:\Software\MyCompany\Advertising" -NewName "Marketing"Identify

Rename multiple files

Get-ChildItem *.txtIdentify

Its page in the reference: Rename-Item.

Parameters

9 in the PowerShell reference
-CredentialNOTE: This parameter is not supported by any providers installed with PowerShell. To impersonate another user, or elevate your credentials when running this cmdlet, use Invoke-Command.
-ForceForces the cmdlet to rename items that can't otherwise be changed, such as hidden or read-only files or read-only aliases or variables. The cmdlet can't change constant aliases or variables. Implementation varies from provider to provider. For more information, see about_Providers. Even using the Force parameter, the cmdlet can't override security restrictions or replace an existing item at the destination name specified by NewName.
-LiteralPathSpecifies a path to one or more locations. The value of LiteralPath is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell PowerShell not to interpret any characters as escape sequences. For more information, see about_Quoting_Rules.
-NewNameSpecifies the new name of the item. Enter only a name, not a path and name. If you enter a path that differs from the path that is specified in the Path parameter, Rename-Item generates an error. To rename and move an item, use Move-Item. You can't use wildcard characters in the value of the NewName parameter. To specify a name for multiple files, use the -replace operator in a regular expression. For more information about the -replace operator, see about_Comparison_Operators.
-PassThruReturns an object that represents the item to the pipeline. By default, this cmdlet does not generate any output.
-PathSpecifies the path of the item to rename.
-UseTransactionIncludes the command in the active transaction. This parameter is valid only when a transaction is in progress. For more information, see about_Transactions.
-ConfirmPrompts you for confirmation before running the cmdlet.
-WhatIfShows what would happen if the cmdlet runs. The cmdlet is not run.