I try to make Script who can move Files older 31 Days and if a file already exists in Destination, the moving File shall be renamed.
I didnt get that happen.
The Code so far is :
Start-Transcript -Path "D:\LOG\LOG_OLDFILES.txt" -append
get-childitem -verbose -Path D:\DATASOURCE -File -Recurse |
where-object {$_.LastWriteTime -lt (get-date).AddDays(-31)} |
move-item -verbose -destination "D:\temp\temp_backup"
So the moving happens, but i get the Failure :
move-item : Cannot create a file when that file already exists.
In that Case he shall rename it to "Filename_"DATE" "
Hope you can help. I tried hard, but i didnt get some If-then things working.
Thank you!