Sql-server – SQL Job Agent Service Account – Access is denied to run Powershell

sql serversql-server-2008-r2

I am trying to run a PowerShell script via the command line via SQL Job.

"C:\Windows\System32\WindowsPowerShell\v1.0" "C:\Test\TestScript.ps1"

I am running the SQL Job from a SQL Server 2008 R2 server. Which permissions does the SQL Job Agent Service Account need to run a PowerShell script? Or is this a windows permission level, not a db permission?

EDIT:
This is the error I am getting
Executed as user: ****.

The process could not be created for step 3 of job ## (reason: Access
is denied). The step failed.

enter image description here
enter image description here

Best Answer

You have to call powershell.exe instead of the foldername

Change this

"C:\Windows\System32\WindowsPowerShell\v1.0" "C:\test\testscript.ps1"

To this

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "C:\test\testscript.ps1"

Testing by creating the same jobstep

enter image description here

The original command

"C:\Windows\System32\WindowsPowerShell\v1.0" "C:\test\testscript.ps1"

The error

Executed as user: ServiceAcc. The process could not be created for step 1 of job .. (reason: Access is denied). The step failed.

Changing the command and running the job again

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "C:\test\testscript.ps1"

Great success

enter image description here