To rename a folder in PowerShell, you can use the Rename-Item cmdlet.
The following method shows how you can do it with syntax.
Method 1: Rename folder
# specify the current folder path
$currentFolderName = "syslog"
# specify new folder name
$newFolderName = "SystemLog"
# Rename the folder
Rename-Item -Path $currentFolderPath -NewName $newFolderName
This example will rename the folder name to “SystemLog“.
The following example shows how you can use this method.
Rename Folder in PowerShell
The Rename-Item cmdlet in PowerShell can be used to rename the folder.
# specify the current folder path $currentFolderName = "syslog" # specify new folder name $newFolderName = "SystemLog" # Rename the folder Rename-Item -Path $currentFolderName -NewName $newFolderName
Output:
In this script, the $currentFolderName variable stores the current folder name. The $newFolderName variable stores the new folder name.
The Rename-Item cmdlet uses the -Path parameter to specify the current folder name and -NewName for the desired new name for the folder. It renames the folder name to the $newFolderName.
After running the script, it will rename the specified folder accordingly. In the screenshot, the current folder name was “syslog“, after running the Rename-Item cmdlet, it changed to “SystemLog“.
Make sure to provide the correct paths for current and new folder names.
Conclusion
I hope the above article on renaming the folder in PowerShell is helpful to you.
You can find more topics about Active Directory tools and PowerShell basics on the ActiveDirectoryTools home page.