Error running Powershell Script in SQL Server Agent

I believe your issue is going to be the SQLPS provider. Since PowerShell steps in SQL Server Agent automatically put you into the context of that provider some commands that work in your normal console will not function the same way. A write up was done here with Set-Location. You basically have to tell SQLPS the provider you want to use.

Your code would look something like below:

set-location -Path Microsoft.PowerShell.Core\FileSystem::"\\server\companydocuments\MyApp\Application Files\"

You could also wrap the remainder into two lines if you wanted to:


cd (Get-ChildItem | Sort-Object name -Descending | Select name -First 1).name
& ".\Application.exe"

The other alternative would be to use operating system command and give powershell.exe c:/path/script.ps1 as command and save your script in script.ps1. This will ensure using OS powershell instead of using provider.