We can make use of the Rename-Item cmdlet to rename files in PowerShell. You can find this cmdlet under Microsoft.PowerShell.Management module.
Syntax:
Rename-Item
-LiteralPath <String>
[-NewName] <String>
[-Force]
[-PassThru]
[-Credential <PSCredential>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Let's take a look at a few examples,
Example 1: One-Liner
PS> Rename-Item ./data_2023_draft.csv -NewName ./data_2023.csv
Rename with Path
PS> Rename-Item -Path D:/files/data_2023_draft.csv -NewName D:/files/data_2023.csv
Example 2: Rename a file using Script
<#
Code2care.org PowerShell Examples
Script to rename a file.
#>
$oldFileName = Read-Host "Enter File Name with Absolute Path To Rename "
$newFileName = Read-Host "Enter a new name for the file "
Rename-Item -Path $oldFileName -NewName $newFileName

Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!