I thought I'd try Powershell for some file maintenance. Thought it might be fun! And now I'm stuck.Can anyone see what I'm doing wrong?I'm having trouble with Rename-Item. This line works from CMD:[code="other"]Dir \\MyServer\MyShare\Transfer\*.txt | Rename-Item –Newname{($_.basename + (get-date -format '_MMddyyyy') + $_.extension)}[/code]But fails when run as part of a script in an Agent Job Step.Here's the entire script:[code="other"]#add the date - files will be named filename_mmddyyyy.txtSet-Location \\MyServer\MyShareDir \\MyServer\MyShare\Transfer\*.txt | Rename-Item –Newname{($_.basename + (get-date -format '_MMddyyyy') + $_.extension)}# copy the .txt files from MyShare\Tranfer to MyShareCopy-Item -Path \\MyServer\MyShare\transfer\*.txt -Destination \\MyServer\MyShare# delete the .txt files from the Transfer folderRemove-Item \\MyServer\MyShare\transfer\*.txt[/code]Here's the error message:Executed as user: MyHouse\sqladmin. A job step received an error at line 3 in a PowerShell script. The corresponding line is 'Dir \\MyServer\MyShare\Transfer\*.txt | Rename-Item ?Newname {($_.basename + (get-date -format '_MMddyyyy') + $_.extension)}'. Correct the script and reschedule the job. The error information returned by PowerShell is: 'A positional parameter cannot be found that accepts argument '($_.basename + (get-date -format '_MMddyyyy') + $_.extension)'. '. Process Exit Code -1. The step failed.
↧