TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

PowerShell Rename-Item

PowerShell Rename-Item with What is PowerShell, History of PowerShell, Features of PowerShell, PowerShell vs CMD, PowerShell Scripting, PowerShell Versions, PowerShell Commands, PowerShell Looping, PowerShell Conditions, PowerShell Array, PowerShell Brackets etc.

<< Back to POWERSHELL

PowerShell Rename-Item | PowerShell Rename file

The PowerShell Rename-Item cmdlet renames an item in a PowerShell provider namespace. It changes the name of a specified item. It does not affect the content of an item being renamed. The ri, rm, rmdir, del, erase, and rd are the aliases of the Rename-Item cmdlet.

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>]

Parameters

-Path

The -Path parameter is used to specify the path of an item to rename.

-LiteralPath

The -LiteralPath parameter is used to specify a path to one or more locations. Its value is used exactly as it is typed. If the path includes the escape characters, enclose it in single quotation marks. Single quotation mark tells the Windows PowerShell that it should not interpret any character as an escape sequence. There is no character in the cmdlet, which is interpreted as a wildcard.

-NewName

The -NewName parameter is used to specify the new name of an item. If a user enters a path that differs from the path specified in the -Path parameter, this parameter generates an error. We cannot use wildcard characters in the value of the-NewName parameter.

-Force

The -Force parameter forces the cmdlet to rename those items which cannot be changed, such as hidden, read-only files, aliases, or variables. It cannot remove constant variables or aliases. Even using the -Force parameter, the cmdlet cannot override security permissions.

-PassThru

The -PassThru parameter returns an object which represents an item to the pipeline. By default, it does not generate any output.

-WhatIf

The -WhatIf parameter displays what would happen if the cmdlet runs. The cmdlet does not execute.

-Confirm

The -Confirm parameter prompts a confirmation before running the cmdlet.

Examples

Example 1: Rename a file

PowerShell Rename-Item

The cmdlet, in this example, renames the file s.txt to c.txt in the current directory.

Example 2: Rename multiple files

PowerShell Rename-Item

The cmdlet, in this example, renames all the .txt files to .doc files.

The Get-ChildItem cmdlet is used in this example to get all the files in the current folder that have a .txt file extension, then pipes them to Rename-Item cmdlet. The value of -NewName is a script block that runs before the value is submitted to the -NewName parameter.






Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf