none
Powershell commands executed by SQL Server Agent fail for executionpolicy error in SQL Server 2012.

    Question

  • Any Powershell command executed inline under the Powershell command mode of the SQL Server Agent fails in Sql Server 2012, even a comment. Before the upgrade, or using a SQL Server 2008 instance on a server on the same OU with the same group security policy, there are no issues.

    Here is the error:

    Executed

    as user: US\xxxxxxxxx. A job step received an error at line 1 in a PowerShell script.

    The corresponding line

    is 'set-executionpolicy Unrestricted -scope process -Force'.

    Correct the script

    and reschedule the job.

    The error information returned

    by PowerShell is: 'Security error. '. Process Exit Code -1. The step failed.


    David z

    Tuesday, November 19, 2013 9:10 PM

Answers

  • So to me this indicates that the Powershell command under the agent is not aware of the group policy for powershell command execution.

    Hello David,

    During installation of SQL Server 2012, have you change the service account of "SQL Server-Agent" to that one which was used for 2008? If not, then now a different account is used and this one may don't have the permissions to execute PowerShell scripts.


    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Wednesday, November 20, 2013 6:08 AM

All replies

  • Prior to SQL Server 2012, we were able to run Powershell commands under the SQL Agent. 

    If I run the same commands on a SQL Server 2008 instance that is under the same group policy, the powershell commands execute correctly.

     After the upgrade to 2012, any and all Powershell commands fail with this message:

    is 'set-executionpolicy Unrestricted -scope process -Force'.

    as user: US\xxxxxxxxx. A job step received an error at line 1 in a PowerShell script.

    and reschedule the job.

    by PowerShell is: 'Security error. '. Process Exit Code -1. The step failed.

    IF I run the command by right clicking on instance name in SSMS and starting Powershell, there are no problems executing the commands. IF I put the commands in a file and execute the script through Powershell.exe via xp_cmdshell, this also works.  So to me this indicates that the Powershell command under the agent is not aware of the group policy for powershell command execution.

    The error information returned

    Correct the script

    Executed

    The corresponding line


    David z


    Tuesday, November 19, 2013 8:52 PM
  • Any Powershell command executed inline under the Powershell command mode of the SQL Server Agent fails in Sql Server 2012, even a comment.   Before the upgrade, or using a SQL Server 2008 instance on a server on the same OU with the same group security policy,  there are no issues.

    Here is the error:

    Executed

    as user: US\xxxxxxxxx. A job step received an error at line 1 in a PowerShell script.

    The corresponding line

    is 'set-executionpolicy Unrestricted -scope process -Force'.

    Correct the script

    and reschedule the job.

    The error information returned

    by PowerShell is: 'Security error. '. Process Exit Code -1. The step failed.

    David z

    Tuesday, November 19, 2013 9:08 PM
  • Check below link if help:

    http://www.mssqltips.com/sqlservertip/2702/setting-the-powershell-execution-policy/


    Please click the Mark as answer button and vote as helpful if this reply solves your problem

    Wednesday, November 20, 2013 1:21 AM
  • In this case, the execution permissions are set by group policy for the OU.  On the same server, Powershell commands will work as executed by the sql agent for ss2008 but not ss2012.  My point is that it is a ss2012 bug.


    David z


    • Edited by David Zamula Wednesday, November 20, 2013 1:37 AM
    Wednesday, November 20, 2013 1:36 AM
  • So to me this indicates that the Powershell command under the agent is not aware of the group policy for powershell command execution.

    Hello David,

    During installation of SQL Server 2012, have you change the service account of "SQL Server-Agent" to that one which was used for 2008? If not, then now a different account is used and this one may don't have the permissions to execute PowerShell scripts.


    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Wednesday, November 20, 2013 6:08 AM
  • I am having the same issue. Were you ever able to get this resolved?

    Thanks

    Robbie

    Wednesday, June 04, 2014 5:13 PM
  • I'm having this problem as well.  If this is a bug it is a major one.  Looks like Powershell scripts cannot be executed from SQL Agent???? 

    Is that right?

    Bryan


    Developer

    Tuesday, June 24, 2014 5:55 PM
  • We can execute powershell scripts. what are you trying to run? One should have right permission to execute the job.

    The below powershell scripts are executed daily to delete abf files.

    --Prashanth

    Tuesday, June 24, 2014 7:04 PM