How to Change File Extensions in Bulk with PowerShell
Changing many file extensions at once, such as turning a batch of .txt files into .md files, is a simple PowerShell task that saves you renaming each one by hand. The command targets a group of files and updates their extensions consistently.
The Command
Get-ChildItem *.txt | Rename-Item -NewName { $_.Name -replace '\.txt$','.md' }
What It Does
`Get-ChildItem *.txt` collects all text files, then `Rename-Item` changes each one’s name. The pattern `’\.txt$’` matches the .txt extension specifically at the end of the name, and it is replaced with .md. The backslash escapes the dot, and the dollar sign anchors the match to the end, so only the extension changes, not any “txt” appearing earlier YYGACOR in a name.
When You’d Use This
This is ideal after downloading or exporting a batch of files with the wrong extension, or when standardizing extensions across a folder, such as unifying .jpeg and .jpg. Changing them one by one is tedious, while this command updates every matching file at once, which is especially useful when preparing files for a tool that expects a particular extension.
Useful Variations
To change a different pair of extensions, swap the values, such as replacing `.jpeg` with `.jpg`. To include subfolders, add `-Recurse` to `Get-ChildItem`. Always confirm your target files first by running just the `Get-ChildItem` part, so you can see exactly which files will be affected before renaming.
If It Doesn’t Work
If the wrong files are affected, your pattern may have matched more than the extension, so the anchored pattern in the example, ending with the dollar sign, helps limit it to the extension only. Preview with `-WhatIf` before running. Remember that changing an extension does not convert the file’s actual format, so renaming an image’s extension will not change how it is truly encoded.
Good to Know
Changing a file’s extension does not convert its contents, only what Windows treats it as, so renaming an image extension will not actually change the image format. Use `-WhatIf` on the `Rename-Item` to preview the changes safely before committing to them.
Putting It Together
The command shown may look dense at first, but it breaks down into clear parts once you have used it a few times. As part of managing files from the terminal, this command earns its place once you are comfortable working without File Explorer. Combined with the others in this area, it lets you handle files in bulk and in scripts far faster than clicking through folders. Like anything in the terminal, the real value comes from trying it on your own system and adapting the variations above to what you actually need, so it is worth experimenting with in a safe, low-stakes situation before relying on it in a script or during troubleshooting. Keeping a note of the commands you find most useful, along with the variations that fit your workflow, turns scattered one-off tricks into a personal reference you can draw on whenever a similar task comes up again.