I have the following powershell script that renames a file with the current date after it has been moved to the destination folder:
##DateStamp
$DateStamp = get-date -uformat "%Y%m%d"
$files = @(get-childitem C:\PowershellTesting\FolderTwo\*.csv)
foreach ($file in $files)
{
get-childitem | rename-item $file -NewName {"CompanyName" + $DateStamp + ".csv"}}
The script actually works in renaming the file, although it still gives me multipler iterations of this error:
rename-item : Cannot rename because item at 'C:\PowershellTesting\FolderTwo\17Feb17082308_CompanyName_20170217.csv' does not exist.
At line:11 char:18
I am guessing this is due to the loop not exiting once the file has been renamed, given that there is only one. Given that it works, I'm guessing I am missing something simple that will help me get rid of the error?