recursive rename-item ?

by Lahru at 2013-05-02 14:00:26

I have a directory with many subdirectories.
Each subdirectory has a file called "Copy.log"
Each month I want to rename the copy.log file in each directory.

$monthNum = get-date -format MM
$monthName = get-date -format MMMM
Rename-item -path "\Server\Dir\SubDir01\copy.log" -newname "$MonthNum-$MonthName-copy.log"
New-item -path "\Server\Dir\SubDir01" -name "copy.log" -itemtype file

Rename-item -path "\Server\Dir\SubDir02\copy.log" -newname "$MonthNum-$MonthName-copy.log"
New-item -path "\Server\Dir\SubDir02" -name "copy.log" -itemtype file
This works, but I was hoping there was a simpler way than re-writing the code for every directory. How can I make this recursive for all copy.log files?
by Nobody at 2013-05-02 15:30:42
Does this work?

$timestamp = get-date -format MM-MMMM
$path = "\Server\Dir"
$logfiles = get-childitem -path "$path" -include "copy.log" -force -recurse

foreach ($log in $logfiles){
rename-item -path $log -newname "$timestamp-copy.log"
New-item -path "$($log.directory)" -name "copy.log" -itemtype file
}
by Lahru at 2013-05-03 11:56:51
Awesome … does just what I Need. TYVM!!