You are here:

WindowsManagement.com > PowerShell > PowerShell 1.0 > Rename-Item
ActiveXperts Network Monitor 2019 proactively manages network servers, devices, databases and more.

Rename-Item - PowerShell 1.0

Microsoft Windows PowerShell is a command-line shell and scripting tool based on the Microsoft .NET Framework. It is designed for system administrators, engineers and developers to control and automate the administration of Windows and applications.

More than hundred command-line tools (so called "cmdlets") can be used to perform system administration tasks and Windows Management Instrumentation (WMI). These cmdlets are easy to use, with standard naming conventions and common parameters, and standard tools for piping, sorting, filtering, and formatting data and objects.

Rename-Item


Description
Back up your Hyper-V VMs Easy & Fast. 100% built for Hyper-V. Free for 2 VMs, forever.

Usage


Options
-path string
       The path(s) to the item(s) to be renamed. Wildcards are permitted.

   -newName string 
       The new name for the item.

   -force
       Override restrictions that prevent the command from succeeding, apart
       from security settings. e.g. Force will create file path directories 
       or override a files read-only attribute, but will not change file permissions.

   -passThru 
        Pass the object created by Rename-Item along the pipeline. 
		
   -credential PSCredential
       Use a credential to validate access to the file. Credential represents
       a user-name, such as "User01" or "Domain01\User01", or a PSCredential
       object, such as the one retrieved by using the Get-Credential cmdlet.
       If you type a user name, you will be prompted for a password.
       This parameter is not supported by any PowerShell core cmdlets or providers.
 
   -whatIf
       Describe what would happen if you executed the command without
       actually executing the command.

   -confirm
       Prompt for confirmation before executing the command.

   CommonParameters:
      -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutVariable.

Example(s)
Rename a file:

PS C:\>rename-item -path c:\docs\dump.csv -newname Report.xls

Rename all .TXT files as .LOG files in the current directory:

PS C:\>get-childitem -Path *.txt | rename-item -NewName {$_.name -replace".txt",".log"}

Because the -Newname parameter does not accept wildcards, the above works by piping the output of Get-ChildItem and then using a -replace expression to calculate all the new filenames.