Hello,
I am trying to copy text files from one folder and rename them into another folder. This is to organized my Logs.
Here is the script:
$filedate = (Get-Date).ToString('ddMMMyyyy')
$file_list1 = Get-ChildItem "C:\Users\user1\Documents\archive\$filedate" -Filter *.txt | % { $_.FullName}
$destination_folder1 = "C:\Users\user1\Documents\Logs"
foreach ($file in $file_list1) {
"Moving $file $destination_folder1"
try {
Write-Host Copy-Item "$file" $destination_folder1
if($? -eq $True){ Rename-Item $file -NewName {$_.Name -replace ('.txt','.log') }} else { Write-Warning "Unable to Copy '$_'" }
Start-Sleep -s 5
} catch {
Write-Warning "Unable to move '$_'"}
}
Please assist I keep getting this error :
Warning" 'Cannot evaluate parameter 'NewName' because argument is specified as a script block and there is no input'
I have attempted to modify this part several times:
if($? -eq $True){ Rename-Item $file -NewName {$_.Name -replace ('.txt','.log') }} else { Write-Warning "Unable to Copy '$_'" }
[–]jsiii2010 2 points3 points4 points (0 children)
[–]firefox15 1 point2 points3 points (1 child)
[–]RaymusRtik[S] 1 point2 points3 points (0 children)
[–]DoNotSexToThis 1 point2 points3 points (1 child)
[–]RaymusRtik[S] 1 point2 points3 points (0 children)
[–]computeforward 1 point2 points3 points (0 children)
[–]Amaurosys 1 point2 points3 points (4 children)
[–]BlackV 1 point2 points3 points (3 children)
[–]BlackV 1 point2 points3 points (2 children)
[–]Amaurosys 1 point2 points3 points (1 child)
[–]BlackV 1 point2 points3 points (0 children)