thotwielder thotwielder - 1 year ago 160
PowerShell Question

powershell rename all files in a folder to a pattern

I am very new to powershell. I have a folder with multiple files, each file name is like:


Need to rename all of them to Filex_yyyymmdd.bak

Answer Source

Something similar should works for you:

Get-ChildItem "C:\temp" |foreach {
    $SplitName = $_.Name -split '_'
    Rename-Item $_.FullName -NewName "$($SplitName[0])_$($SplitName[2])$($SplitName[3])$($SplitNa‌​me[4]).bak"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download