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-Item
Secondary Sidebar
PowerShell Tutorial
  • 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
  • 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
  • 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
  • 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
  • Interview Questions
    • PowerShell Interview Questions

Related Courses

Shell Scripting Course

All in One Data Science Courses

Data Visualization Courses

PowerShell Rename-Item

By Chirag NagarekarChirag Nagarekar

PowerShell Rename - Item

Introduction to PowerShell Rename-Item

Rename-Item cmdlet in PowerShell is used to rename items like files, folders, registry, certificates, etc. This cmdlet just renames items but not their actual content or cannot move items to a different location.

Syntax:

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

Parameters in PowerShell Rename-Item

Following are the parameters for the PowerShell Rename-Item:

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

  • Path: Source path of the Item. This path should be in a string format and must be identical. You can specify wildcard character (*) but path should resolve only one item instead of multiple items.
  • NewName: Destination file name. By default, it will take the same source path, when you explicitly specify different paths it will generate an error. You cannot use a wildcard (*) character in a new name. It is possible to rename multiple files and extensions.
  • Force: Renames item name that cannot be changed. Files or folders which are read-only or hidden, this parameter allows them to rename forcefully. This parameter cannot change constant alias or the variable.
  • PassThru: By default, Rename-Object doesn’t generate any output. This parameter allows the output to display in the console.
  • Credential: If your destination item is in a different domain or work-group, you can use this parameter to connect the destination path with different credentials.
  • Whatif: This parameter is used to notify what operation going to perform if this command runs, without actually running the command.
  • LiteralPath: This parameter also specifies the path of an item to rename. No characters are interpreted as wildcard characters. If the path includes the special character then they need to be enclosed in a single quotation so PowerShell will not interpret any character as escape sequences.
  • Confirm: This parameter prompts the user before performing the rename operation on the item.
  • UseTranscation: This parameter includes the command in the active transaction. This parameter is valid only when the transaction is in progress.
  • <CommonParameters>: The below parameters are supported by common parameters. ErrorAction, ErrorVariable, WarningAction, WarningVariablem OutBuffer, PipelineVariable, and OutVariable.

Examples to Implement PowerShell Rename-Item

Below is the example to implement in PowerShell Rename-Item:

Example #1 –  Rename-Item

Code:

Rename-Item D:\Temp\Putty.log -NewName Putty1.log

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,650 ratings)

In the above example, when you don’t provide the destination path for the file to rename, it will by default take the same source path. You can also rename items without specifying –Newname parameter. To do so, just provide the space between the old name and new name. For example,

Rename-Item D:\Temp\Putty.log Putty1.log

You can also rename the folder as shown below.

Rename-Item D:\Temp -NewName Temp1

Example #2 – Rename-Item with Passthru parameter

To check the output of the command in the console, use -Passthru parameter.

Code:

Rename-Item D:\Temp\Putty.log -NewName Putty1.log -PassThru

Output:

PowerShell Rename-Item - 1

If you provide the different destination path then it will generate an error because this cmdlet can’t perform the move operation.

Rename-Item D:\Temp\putty.log -NewName D:\putty1.log -PassThru

Output:

PowerShell Rename-Item - 2

Example #3 – Rename-ChildItem with Whatif Parameter

When you use the whatif parameter, it will show you the action command is going to perform, without actually running the command.

Rename-Item D:\Temp\cars.xml -NewName cars1.xml -PassThru -WhatIf

Output:

 Whatif Parameter

Example #4 – Rename-ChildItem with Confirm parameter

This parameter will ask for user confirmation before renaming the item.

Code:

Rename-Item D:\Temp\cars.xml -NewName cars1.xml –Confirm

Output:

Confirm parameter

You can also provide the value $true or $false to confirm the parameter. When $true value is provided it will prompt for user confirmation. When you $false value is provided, it will not prompt for the user confirmation and directly rename the item and this is the default option in –confirm parameter.

Rename-Item D:\Temp\cars.xml -NewName cars1.xml -Confirm:$true

Rename-Item D:\Temp\cars.xml -NewName cars1.xml -Confirm:$false

Example #5 – Rename registry value

Like file rename, you can also rename registry values.

Code:

Rename-Item HKLM:\SYSTEM\CurrentControlSet\Control\test -NewName Test2

Rename-Item HKLM:\SECURITY\Policy\Data -NewName Data1

Example #6 – Rename multiple files extension with Rename-Item

To rename multiple files extension, you can use the below command to replace them.

Code:

PS C:\WINDOWS\system32> Get-ChildItem D:\Temp\* -Include *.html | Rename-Item -NewName {$_.Name -replace '.html','.htm'} -PassThru

To rename multiple files or folders you need to use the loop.

Output:

Rename multiple files

Conclusion

Rename-Item is a good tool to rename single or multiple files, extensions, folders, registry, etc. But it cannot move or copy the files. For them, there are different cmdlets available.

Recommended Articles

This is a guide to PowerShell Rename-Item. Here we discuss the basic introduction, parameter, examples to implement with appropriate codes and outputs. You can also go through our other related articles to learn more –

  1. Set Variable in PowerShell
  2. Variable in PowerShell
  3. Hashtable in PowerShell
  4. Examples to Implement PowerShell New-Item
Popular Course in this category
All in One Data Science Bundle (360+ Courses, 50+ projects)
  360+ Online Courses |  1500+ Hours |  Verifiable Certificates |  Lifetime Access
4.7
Price

View Course

Related Courses

Shell Scripting Training (4 Courses, 1 Project)4.9
Data Visualization Training (15 Courses, 5+ Projects)4.8
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