PowerShell Script Not Working on SQL Server Job Step

I hope you’re doing fine!
I’ve some .CSV files generated in a shared folder (SERVER01DIRCurrent) and would like to copy to another folder in same server01 (SERVER01DIRArchive). Script must to copy, rename files adding timestamp and then removing from source folder. PS script works very well on Powershell ISE or Windows Powershell, but, when I try to schedule same script on SQL Server Job, I’m receiving errors below.

$source = "\SERVER01DIRCurrent" $destination = "\SERVER01DIRArchive"

Get-ChildItem $source -Recurse -Include *.csv | % {
    $name = $_.Name.Split(".")(0) + "_" + ($_.CreationTime | Get-Date -Format yyyymmdd) + "_" + ($_.CreationTime | Get-Date  -Format hhmmss) + ".csv"
    #$name = "Finished_" + ($_.CreationTime | Get-Date -Format yyyymmdd) + "_" + ($_.CreationTime | Get-Date  -Format hhmmss) + ".csv"
    #$name = "Finished_" + $_.Name.Split(".")(0) +  "_" + ($_.CreationTime | Get-Date -Format yyyymmdd) + "_" + ($_.CreationTime | Get-Date  -Format hhmmss) + ".csv"
    Rename-Item $_ -NewName $name
    Move-Item "$($_.Directory)$name" -Destination $destination }

I’ve received error below:

Message
Unable to start execution of step 1 (reason: line(9): Syntax error). The step failed.

After receive error above, I’ve changed Line(9) as below:

$source = "\SERVER01DIRCurrent"
$destination = "\SERVER01DIRArchive"

Get-ChildItem $source -Recurse -Include *.csv | % {
    $name = $_.Name.Split(".")(0) + "_" + ($_.CreationTime | Get-Date -Format yyyymmdd) + "_" + ($_.CreationTime | Get-Date  -Format hhmmss) + ".csv"
    #$name = "Finished_" + ($_.CreationTime | Get-Date -Format yyyymmdd) + "_" + ($_.CreationTime | Get-Date  -Format hhmmss) + ".csv"
    #$name = "Finished_" + $_.Name.Split(".")(0) +  "_" + ($_.CreationTime | Get-Date -Format yyyymmdd) + "_" + ($_.CreationTime | Get-Date  -Format hhmmss) + ".csv"
    Rename-Item $_ -NewName $name
    Move-Item "\SERVER01DIRCurrent$name" -Destination $destination
}

Then, received another error:

*Message
The job script encountered the following errors. These errors did not stop the script:
A job step received an error at line 4 in a PowerShell script.
The corresponding line is ‘Get-ChildItem $source -Recurse -Include .csv | % { ‘.
Correct the script and reschedule the job.
The error information returned by PowerShell is:
‘Cannot find path ‘SERVER01DIRCurrent’ because it does not exist. ‘.
Process Exit Code 0. The step succeeded.

After that, I’ve tried to change line(9) again, using $source parameter:

Move-Item $source + "" + $name -Destination $destination

But, it didn’t work and return same error above: ‘Cannot find path ‘SERVER01DIRCurrent’ because it does not exist. ‘.

Please, could you help me how to solve it? It looks like “$($_.Directory)…” is not working on SQL job. Not sure why and how to solve it.
Thanks!