This PS script works in the PS window on my SQL server 2012, but does not work as a SQL Job step. The SQL job step errors with "error information returned by PowerShell is: 'Cannot call method. The provider does not support the use of filters. '. Process Exit Code -1. The step failed." Is it possible for the version of PS and the version pf PS used by SQL to be different? Suggestions for a fix? Basically need to copy the latest version of a file to a different location with different name.
$filterNTC="*_filename.csv" $dir = "\\networkloc\folder\folder\folder\folder\folder\" $latestNTC = Get-ChildItem -Path $dir -Filter $filterNTC | Sort-Object LastAccessTime -Descending | Select-Object -First 1 $sourcefile = "\\networkloc\folder\folder\folder\folder\folder\" + $latestNTC.name Copy-Item -Path $sourcefile -Destination D:\folder\folder\folder\folder\filename.csv
Answer by Magnus Ahlkvist ·
I'm gonna guess it's a Powershell jobstep you're configuring, not a SQL job step.
Anyway, if you want to execute Powershell, you don't want to run a Powershell jobstep, because the Powershell jobstep will execute using SQLPS.exe which is not the same as Powershell.exe (or pwsh.exe for Powershell core).
To execute using powershell.exe or pwsh.exe, you want to create a CmdExec jobstep, and run the command
powershell.exe -File <path to your .ps1 file containing your script
Or pwsh.exe with the same parameters for Powershell core.