EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials PowerShell Tutorial PowerShell Rename Folder
Secondary Sidebar
PowerShell Tutorial
  • Functions
    • PowerShell Functions
    • PowerShell String Functions
    • powershell nslookup
    • PowerShell here string
    • PowerShell Wildcards
    • Regex in PowerShell
    • PowerShell not like
    • PowerShell Filter
    • PowerShell Sleep
    • PowerShell where
    • PowerShell join string
    • PowerShell Exit
    • PowerShell null
    • PowerShell Dictionary
    • PowerShell Location
    • PowerShell Start-Service
    • PowerShell is not digitally signed
    • PowerShell Uptime
    • PowerShell Create Directory
    • PowerShell Trim
    • PowerShell Join-Path
    • PowerShell Execution Policy
    • PowerShell SubString
    • PowerShell Format Table
    • PowerShell Import Module
    • PowerShell ForEach Object
    • PowerShell Alias
    • PowerShell Scheduled Task
    • PowerShell Convert String to Date
    • PowerShell Split String
    • PowerShell Multiline String
    • PowerShell MultiLine Comment
    • PowerShell Rename Folder
    • PowerShell Delete Folder
    • PowerShell String Replace
    • PowerShell join
    • PowerShell xcopy
    • PowerShell Base64
    • PowerShell Tail
    • PowerShell User List
    • PowerShell remove User from group
    • PowerShell JSON Format
    • PowerShell Send Mail
    • PowerShell Convert to String
    • PowerShell Start-Process
    • PowerShell change directory
    • PowerShell Open File
    • PowerShell Batch File
    • PowerShell ZIP
    • PowerShell unzip
    • PowerShell XML
    • PowerShell XML Parsing
    • Remote PowerShell
    • PowerShell Escape Character
    • PowerShell scriptblock
    • PowerShell Executable Location
    • PowerShell Import-CSV?
    • PowerShell Export CSV
  • Basics
    • PowerShell Restart Service
    • PowerShell comment
    • PowerShell Map Network Drive
    • PowerShell Append to File
    • PowerShell print
    • What is PowerShell
    • Uses Of Powershell
    • PowerShell Empire
    • PowerShell Parameter
    • PowerShell Stop Service
    • PowerShell Versions
    • How To Install PowerShell
    • PowerShell uninstall module
    • How to Use PowerShell?
    • PowerShell Logging
    • PowerShell Tools
    • PowerShell Commands
    • PowerShell Version Command
    • PowerShell Administrator
    • PowerShell Modules
    • PowerShell Registry
    • PowerShell block Comment
    • PowerShell Verbs
    • PowerShell list
    • PowerShell add user to group
    • PowerShell Write to Console
    • Variable in PowerShell
    • PowerShell New Line
    • PowerShell prompt for input
    • PowerShell File Extension
    • Powershell Remotesigned
    • PowerShell Write to File
    • PowerShell Ping
    • PowerShell wget
    • PowerShell Global variable
    • PowerShell Get-ADGroup
    • Array in PowerShell
    • PowerShell Multidimensional Array
    • PowerShell Array of Strings
    • PowerShell? join array
    • Useful PowerShell Scripts
    • String in PowerShell
    • PowerShell Switch Statement
    • PowerShell Function Parameters
    • PowerShell vs PowerShell ISE
    • PowerShell test-connection
    • PowerShell Test-NetConnection
    • PowerShell GUI
    • PowerShell Variable in String
    • PowerShell Active Directory
  • Variables
    • PowerShell Variables
    • PowerShell Environment Variables
    • PowerShell set environment variable
    • Hashtable in PowerShell
    • Set Variable in PowerShell
  • Operators
    • PowerShell Operators
    • Comparison Operators in PowerShell
    • Logical Operators in PowerShell
    • PowerShell Boolean
    • PowerShell Like Operator
  • cmdlet
    • PowerShell Wait
    • PowerShell Match
    • cmdlets in PowerShell
    • Start PowerShell from cmd
    • Add-Content in PowerShell
    • Get Help in PowerShell
    • PowerShell Copy-Item
    • PowerShell Remove-Item
    • PowerShell Move-Item
    • Get Command in PowerShell
    • PowerShell Run Command
    • Windows PowerShell ISE
    • Windows Powershell Commands
    • WinRM PowerShell
    • PowerShell Date
    • Powershell Write-Host
    • PowerShell Get-ChildItem
    • PowerShell Sort-Object
    • PowerShell Where Object
    • PowerShell Set-Content
    • PowerShell Set-Location
    • PowerShell Invoke-Command
    • PowerShell Invoke-Webrequest
    • PowerShell Get-Location
    • PowerShell Get-Date
    • PowerShell Get-Service
    • PowerShell Test-Path
    • Powershell Module Path
    • PowerShell Out-File
    • PowerShell if File Exists
    • Powershell Copy File
    • PowerShell Delete File
    • PowerShell New-Item
    • PowerShell Rename-Item
    • PowerShell ComputerName
    • PowerShell Get-Content
    • PowerShell Get-Item
    • PowerShell Get-ADUser
    • PowerShell Grep
    • PowerShell Concatenate String
    • PowerShell Get-Process
    • PowerShell Count
    • PowerShell pause
  • Control Statements
    • If Statement in PowerShell
    • If Else in PowerShell
    • Else If in PowerShell
    • Loops in PowerShell
    • For loop in PowerShell
    • PowerShell While Loop
    • PowerShell do while
    • PowerShell Loop through Array
    • PowerShell add to array
    • PowerShell ForEach Loop
    • PowerShell Break
    • PowerShell Continue
    • Switch Case in PowerShell
    • PowerShell If-Not
    • Try-catch in PowerShell
  • Interview Questions
    • PowerShell Interview Questions

Related Courses

Shell Scripting Course

All in One Data Science Courses

Data Visualization Courses

PowerShell Rename Folder

By Priya PedamkarPriya Pedamkar

PowerShell Rename Folder

Introduction to PowerShell Rename Folder

In PowerShell, renaming an item like a folder or a file name is achieved with the help of Rename-Item Cmdlet. It just changes the item and not the contents of the item. This is different from moving the item and can’t be used to move the item. The folder/item that is being renamed must be present else the cmdlet will be thrown an error. This can also be used to rename multiple items/folders simultaneously. The article will be covering in detail on the various parameters that are associated with the Rename-Item cmdlet, their use and how renaming works in PowerShell.

Syntax and Parameters

The below is the syntax of the Rename-Item Cmdlet:

NAME
Rename-Item
SYNTAX
Rename-Item [-Path] <string> [-NewName] <string> [-Force] [-PassThru] [-Credential <pscredential>] [-WhatIf] [-Confirm] [-UseTransaction]  [<CommonParameters>] Rename-Item [-NewName] <string> -LiteralPath<string> [-Force] [-PassThru] [-Credential <pscredential>] [-WhatIf] [-Confirm] [-UseTransaction]  [<CommonParameters>] ALIASES
rni
ren

Example:

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (86,584 ratings)

Rename-Item -Path "c:\test\test1.txt" -NewName "test2.txt"
The above cmdlet will rename the file test1.txt to test2.txt without altering the content
Rename-Item -Path "c:\test\" -NewName "test2"
The above cmdlet will rename the folder test to test2

Parameters:

  • Confirm: This is used to get the confirmation of the user before executing the cmdlet. It’s an optional parameter. Its default value is false, and its type is switch parameter. The alias for this parameter is cf. Default value is false. It doesn’t accept pipeline characters as input and wild card characters are also not accepted.
  • Credential: This is for impersonation purpose or elevating the account on which the cmdlet is being run. To use this, invoke command must be used and it is not supported by any providers installed within PowerShell. Its type is PS Credential. Its default value is current user. It accepts pipeline input but doesn’t accept wildcard characters.
  • Force: Hidden folders or items or read-only folders or read-only items can’t be renamed unless force parameters are explicitly mentioned in the rename-item cmdlet. Constant variables and aliases can’t also be renamed. The security restrictions are still maintained even though force parameter is used. Its type is switch parameter. Its default value is false.It doesn’t accept pipeline characters as input and wild card characters are also not accepted.
  • Literal Path: This denotes or represents the item or items path to be renamed. The value whatever is typed as the literal value. None of the characters are interpreted as wild cards. In case if the path contains escape characters, it must be enclosed within single quotation to inform PowerShell not to interpret as escape sequence. This is a mandatory parameter.
  • -NewName: This denotes the new name of the item to which the item must be renamed. Only a name must be entered and not a path. The cmdlet will understand whether a path or a file must be renamed. Wild cards are not accepted. Replace operator must be used when multiple items are to be renamed. Its type is string. Default value is none. It accepts pipeline input, but wild card characters are not accepted.
  • PassThru: This doesn’t generate any input. It is used to return items to be the pipeline. It’s an optional parameter. Its type is switch parameter. Its default value is false.It doesn’t accept pipeline characters as input and wild card characters are also not accepted.
  • Path: This is a mandatory parameter. It denotes the path of the item to be renamed. Its type is string. Its default value is none. Pipeline input is accepted whereas wild card characters are not considered.
  • WhatIf: This doesn’t produce any output. It just shows what will happen if the cmdlet is run. Its type is switch parameter. Its alias is wi. Its default value is false.It doesn’t accept pipeline characters as input and wild card characters are also not accepted.

The rename-item cmdlet supports only with providers that are being exposed. To find the list of available providers in our session, run the below cmdlet.

Input:

Get-PsProvider

Output:

PowerShell Rename Folder-1.1

List of Providers in the current PowerShell Session

Name       Capabilities Drives     
Registry ShouldProcess, Transactions {HKLM, HKCU}
Alias ShouldProcess {Alias}
Environment ShouldProcess {Env}
FileSystem Filter, ShouldProcess, Credentials {C}
Function ShouldProcess {Function}
Variable ShouldProcess {Variable}

Examples of PowerShell Rename Folder

Following are the example are given below:

Example #1

Input:

Write-Host "Welcome to the demo of renaming folder"
write-host "Renaming Test1 to test9 in the below example"
Write-Host "List of Folders before renaming"
Get-ChildItem -Path C:\Vignesh\Test
Rename-Item -Path C:\Vignesh\Test\Test1 -NewName Test9
Write-Host "Renaming completed successfully"
Write-Host "List of folders after renaming"
Get-ChildItem -Path C:\Vignesh\Test
Write-Host "Renaming a file"
Write-Host "File name before renaming"
Get-ChildItem -Path C:\Vignesh\Test\Actual1239
Write-Host "After Renaming"
Rename-Item -Path C:\Vignesh\Test\Test9\test.txt -NewNameactual.txt
Get-ChildItem -Path C:\Vignesh\Test\Actual1239

Output:

PowerShell Rename Folder-1.2

PowerShell Rename Folder-1.3

Example #2

Input:

write-host "Welcome to the demo of bulk renaming of folders and files"
Write-Host "Renaming multiple folders at once"
Write-Host "before renaming the folders names are as below"
Get-ChildItem -Path C:\Vignesh\Test
Get-ChildItem C:\Vignesh\Test -Recurse | Rename-Item -NewName{ $_.name -replace 'Actual', 'Actual123'}
Write-Host "After renaming the folders"
Write-Host "Now the folders name are as below"
Get-ChildItem -Path C:\Vignesh\Test
Write-Host "Renaming txt files to doc"
Write-Host "Before Renaming the files are as below"
Get-ChildItem C:\Vignesh\Test\Actual1239
Write-Host "Renaming all txt files to log"
Get-ChildItem C:\Vignesh\Test\Actual1239 | Rename-Item -NewName{ $_.Name -replace '.txt','.log' }
Write-Host "After renaming"
Get-ChildItem C:\Vignesh\Test\Actual1239

Output:

PowerShell Rename Folder-2.1

Output-2.2

Example #3

Input:

Write-Host "Moving folders within a directory to another directory"
Write-Host "Before moving the list of files in the source directory is"
Get-ChildItem  C:\Vignesh\Script
Write-Host "List of files in destination directory"
Get-ChildItem C:\Vignesh\Test
Write-Host "Moving the folders from script to test"
Get-ChildItem -Path C:\Vignesh\Script | Move-Item -Destination C:\Vignesh\Test
Write-Host "Folders moved successfully"
Write-Host "Folders now in source"
Get-ChildItem  C:\Vignesh\Script
Write-Host "Folders now in Destination"
Get-ChildItem  C:\Vignesh\Test
Write-Host "Renaming file name with todays date and time"
Write-Host "File names before renamin"
Get-ChildItem C:\Vignesh\Test\Actual1239
$curDateTime = Get-Date -Format yyyyMMdd-HHmmss
Get-ChildItemC:\Vignesh\Test\Actual1239  -Recurse |
Rename-Item -NewName {$_.Basename + '_' + $curDateTime + $_.Extension }
Write-Host "File names after renaming"
Get-ChildItem C:\Vignesh\Test\Actual1239

Output:

Output-3.1

Output-3.2

Conclusion

Thus, the article covered in detail about the Rename-Item cmdlet. It can be used to rename folders, files or any item. The article also demonstrated appropriate example scripts on how to rename a single file, single folder, multiple files, multiple folders and how a file name can be appended with today date. To learn more about this cmdlet in detail, it is advisable to write sample scripts and practice them.

Recommended Articles

This is a guide to PowerShell Rename Folder. Here we also discuss the Introduction and syntax and parameters along with different examples and its code implementation. You may also have a look at the following articles to learn more –

  1. PowerShell Get-Item
  2. A Quick Glance of PowerShell If-Not
  3. PowerShell Send Mail | Examples
  4. PowerShell Get-Service
  5. PowerShell Continue
Popular Course in this category
PowerShell Training (2 Courses, 1 Project)
  2 Online Courses |  1 Hands-on Project |   4+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Shell Scripting Training (4 Courses, 1 Project)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
Data Visualization Training (15 Courses, 5+ Projects)4.7
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more