How to Rename Folders to Uppercase or Lowercase Using PowerShell?

As an IT professional working for a client in the United States, I recently encountered a situation where I needed to standardize the naming convention of folders across multiple directories. PowerShell is perfect for this. In this tutorial, I will explain how to use PowerShell to rename folders to uppercase or lowercase.

Now, let me explain everything with examples.

Rename Folders to Uppercase Using PowerShell

To rename folders to uppercase using PowerShell, you can use the Get-ChildItem cmdlet to retrieve the folders and then pipe them to the Rename-Item cmdlet. Here’s an example:

Get-ChildItem -Directory | ForEach-Object {
    Rename-Item $_.FullName -NewName $_.Name.ToUpper()
}

Let’s break down this code:

  1. Get-ChildItem -Directory retrieves all the folders in the current directory.
  2. The results are piped (|) to the ForEach-Object cmdlet, which processes each folder individually.
  3. Rename-Item is used to rename the folder, with the following parameters:
    • $_.FullName represents the full path of the current folder.
    • -NewName specifies the new name for the folder.
    • $_.Name.ToUpper() converts the current folder name to uppercase.

For example, if you have folders named “new york”, “los angeles”, and “chicago”, running this command will rename them to “NEW YORK”, “LOS ANGELES”, and “CHICAGO”, respectively.

Here is an example:

Get-ChildItem -Directory -Path "C:\MyFolder" | ForEach-Object {
    Rename-Item $_.FullName -NewName $_.Name.ToUpper()
}

I executed the above PowerShell script, and you can see the exact output in the screenshot below:

powershell rename folder to uppercase

Rename Folders in Subdirectories

To rename folders in subdirectories as well, you can add the -Recurse parameter to the Get-ChildItem cmdlet:

Get-ChildItem -Directory -Recurse | ForEach-Object {
    Rename-Item $_.FullName -NewName $_.Name.ToUpper()
}

This command will traverse all subdirectories and rename any folders found to uppercase.

Check out How to Rename Multiple Files Using PowerShell?

Rename Folders to Lowercase Using PowerShell

To rename folders to lowercase, you can use a similar approach, but with the ToLower() method instead of ToUpper():

Get-ChildItem -Directory | ForEach-Object {
    Rename-Item $_.FullName -NewName $_.Name.ToLower()
}

This command will rename folders like “NEW YORK”, “LOS ANGELES”, and “CHICAGO” to “new york”, “los angeles”, and “chicago”, respectively.

Here is an example:

Get-ChildItem -Directory -Path "C:\MyFolder" | ForEach-Object {
    Rename-Item $_.FullName -NewName $_.Name.ToLower()
}

The exact output is in the screenshot below after I executed the PowerShell script above using VS code.

powershell rename folder to lowercase

Rename Folders in Subdirectories to Lowercase

To include subdirectories when renaming folders to lowercase, use the -Recurse parameter with Get-ChildItem:

Get-ChildItem -Directory -Recurse | ForEach-Object {
    Rename-Item $_.FullName -NewName $_.Name.ToLower()
}

Read How to Check if a File Exists and Rename it Using PowerShell?

Rename Folders to Uppercase or Lowercase Using PowerShell Examples

Now, let me show you some more examples of renaming folders to uppercase or lowercase using PowerShell.

  1. Renaming folders in a specific directory:
Get-ChildItem -Directory -Path "C:\Users\FewLines\Documents" | ForEach-Object {
    Rename-Item $_.FullName -NewName $_.Name.ToUpper()
}

This command renames folders in the “C:\Users\FewLines\Documents” directory to uppercase.

  1. Renaming folders matching a specific pattern:

Now, let me show you how to rename folders with a matching specific pattern using PowerShell.

Get-ChildItem -Directory -Filter "*project*" | ForEach-Object {
    Rename-Item $_.FullName -NewName $_.Name.ToLower()
}

This command renames folders containing the word “project” in their name to lowercase.

  1. Renaming folders with a specific file extension:

Here is a complete PowerShell script to rename folders with a specific file extension.

Get-ChildItem -Directory -Recurse | Where-Object { $_.Name -like "*.bak" } | ForEach-Object {
    Rename-Item $_.FullName -NewName $_.Name.ToUpper()
}

This command renames folders with the “.bak” extension to uppercase, including those in subdirectories.

Conclusion

In this tutorial, I explained how to rename folders to uppercase or lowercase using PowerShell. By using the Get-ChildItem and Rename-Item cmdlets, you can automate the process of standardizing folder names across your file system. Whether you need to rename folders in a specific directory, match a particular pattern, or include subdirectories, you can use PowerShell to achieve this.

You may also like the following tutorials:

>
Download User registration canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial

FREE Power Platform Tutorial PDF

Download 120 Page FREE PDF on Microsoft Power Platform Tutorial. Learn Now…