thotwielder thotwielder - 9 months ago 62
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


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"