PowerShell Sql job

  • Hi,
    I 'm working to launch with a Sql Agent Job a powershell script. (the script is saved into network share because used by different Sql Instances)
    If I run it from Windows Powershell with the Sql Service account the script runs correctly, if I run the sql job, I get this error:

    Executed as user: domain\xxxx A job step received an error at line 1 in a PowerShell script.
    The corresponding line is '\\share\folder$\Sync.ps1.
    Correct the script and reschedule the job.
    The error information returned by PowerShell is: 'File \\share\folder$\Sync.ps1 cannot be loaded.
    The file \\share\folder$\Syncl.ps1 is not digitally signed.
    You cannot run this script on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170. '. Process Exit Code -1. The step failed.

    I'm working with Sql 2016 on a Windows 2016 Server.
    The same script works well on Sql 2014 on a Windows 2012R2 Server.

    Do you have any idea how to solve this issue? 
    Thanks

  • vincenzo_capelli - Friday, April 20, 2018 2:06 PM

    Hi,
    I 'm working to launch with a Sql Agent Job a powershell script. (the script is saved into network share because used by different Sql Instances)
    If I run it from Windows Powershell with the Sql Service account the script runs correctly, if I run the sql job, I get this error:

    Executed as user: domain\xxxx A job step received an error at line 1 in a PowerShell script.
    The corresponding line is '\\share\folder$\Sync.ps1.
    Correct the script and reschedule the job.
    The error information returned by PowerShell is: 'File \\share\folder$\Sync.ps1 cannot be loaded.
    The file \\share\folder$\Syncl.ps1 is not digitally signed.
    You cannot run this script on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170. '. Process Exit Code -1. The step failed.

    I'm working with Sql 2016 on a Windows 2016 Server.
    The same script works well on Sql 2014 on a Windows 2012R2 Server.

    Do you have any idea how to solve this issue? 
    Thanks

    Did you check the execution policies? There are different scopes for the execution policy so that could be the difference between the two servers. You can find more information in the following article. Check the section on setting the scope and check on both servers:
    Set-ExecutionPolicy

    Sue

  • Sue_H - Friday, April 20, 2018 2:14 PM

    vincenzo_capelli - Friday, April 20, 2018 2:06 PM

    Hi,
    I 'm working to launch with a Sql Agent Job a powershell script. (the script is saved into network share because used by different Sql Instances)
    If I run it from Windows Powershell with the Sql Service account the script runs correctly, if I run the sql job, I get this error:

    Executed as user: domain\xxxx A job step received an error at line 1 in a PowerShell script.
    The corresponding line is '\\share\folder$\Sync.ps1.
    Correct the script and reschedule the job.
    The error information returned by PowerShell is: 'File \\share\folder$\Sync.ps1 cannot be loaded.
    The file \\share\folder$\Syncl.ps1 is not digitally signed.
    You cannot run this script on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170. '. Process Exit Code -1. The step failed.

    I'm working with Sql 2016 on a Windows 2016 Server.
    The same script works well on Sql 2014 on a Windows 2012R2 Server.

    Do you have any idea how to solve this issue? 
    Thanks

    Did you check the execution policies? There are different scopes for the execution policy so that could be the difference between the two servers. You can find more information in the following article. Check the section on setting the scope and check on both servers:
    Set-ExecutionPolicy

    Sue

    Yes, I tried lot of execution policy config but nothing it doesn't work.
    Now the config is this:

       Scope ExecutionPolicy
       ----- ---------------
    MachinePolicy    Bypass
     UserPolicy    Bypass
      Process   Undefined
    CurrentUser    Bypass
    LocalMachine  Unrestricted

    Any idea?
    Thanks
    Regards

  • vincenzo_capelli - Saturday, April 21, 2018 5:36 AM

    Sue_H - Friday, April 20, 2018 2:14 PM

    vincenzo_capelli - Friday, April 20, 2018 2:06 PM

    Hi,
    I 'm working to launch with a Sql Agent Job a powershell script. (the script is saved into network share because used by different Sql Instances)
    If I run it from Windows Powershell with the Sql Service account the script runs correctly, if I run the sql job, I get this error:

    Executed as user: domain\xxxx A job step received an error at line 1 in a PowerShell script.
    The corresponding line is '\\share\folder$\Sync.ps1.
    Correct the script and reschedule the job.
    The error information returned by PowerShell is: 'File \\share\folder$\Sync.ps1 cannot be loaded.
    The file \\share\folder$\Syncl.ps1 is not digitally signed.
    You cannot run this script on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170. '. Process Exit Code -1. The step failed.

    I'm working with Sql 2016 on a Windows 2016 Server.
    The same script works well on Sql 2014 on a Windows 2012R2 Server.

    Do you have any idea how to solve this issue? 
    Thanks

    Did you check the execution policies? There are different scopes for the execution policy so that could be the difference between the two servers. You can find more information in the following article. Check the section on setting the scope and check on both servers:
    Set-ExecutionPolicy

    Sue

    Yes, I tried lot of execution policy config but nothing it doesn't work.
    Now the config is this:

       Scope ExecutionPolicy
       ----- ---------------
    MachinePolicy    Bypass
     UserPolicy    Bypass
      Process   Undefined
    CurrentUser    Bypass
    LocalMachine  Unrestricted

    Any idea?
    Thanks
    Regards

    At the beginning of the script, try adding: Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
    It will bypass for just that session.

    Sue

  • I had to create a powershell proxy account to run ps from sql

  • Chris Hurlbut - Tuesday, April 24, 2018 2:23 PM

    I had to create a powershell proxy account to run ps from sql

    I solved in this way.
    I modified the execution policy for the sql agent service account in this way:

       Scope ExecutionPolicy
       ----- ---------------
    MachinePolicy  Unrestricted
     UserPolicy  Unrestricted
      Process   Undefined
    CurrentUser  Unrestricted
    LocalMachine  Unrestricted

    this was not enough.
    Finally I put into Internet Explorer trusted sites the network share (file://share.domain.org) where the script is saved.
    Regards

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply