# Batch Rename Files Using PowerShell in Windows
## Metadata
**Status**:: #x
**Zettel**:: #zettel/fleeting
**Created**:: [[2024-04-05]]
**Parent**:: [[PowerShell]], [[♯ Windows]]
## Synopsis
```powershell
Get-ChildItem -File -Recurse | % { Rename-Item -Path $_.PSPath -NewName $_.Name.replace(".mkv.mp4",".mp4")}
```
Or using a scriptblock in `Rename-Item`
```powershell
Get-ChildItem -Recurse -Include *.ps1 | Rename-Item -NewName { $_.Name.replace(".ps1",".ps1.bak") }
```
Filters:
- `-Include *.ps1`
## Complex ScriptBlock
### Suppressing Return Values
```powershell
ls | Rename-Item -Confirm -NewName { $null = $_.Name -match "S01E.."; "Haikyuu $($Matches[0]).mkv" }
```
Alternatives:
```
$null = test
[void](test)
test | out-null
```
References:
- [Suppressing return values in PowerShell functions](https://devblogs.microsoft.com/powershell/suppressing-return-values-in-powershell-functions/)
- (**Reference**:: [[dugas on Stack Overflow - How can I bulk rename files in PowerShell (Highlights)]])
### `ForEach-Object`
```powershell
ls | ? { $_.Name -match "S01E\d{2}" } | % {
$newName = "Haikyuu $($Matches[0]).mkv"
Rename-Item -Path $_.FullName -NewName $newName -Confirm
}
```