So the text of the job step is the Powershell call above? Try embedding that command in a BAT file. I have had similar problem with CmdExec jobs. Not signed PowerShell scripts, but when I have put the command to execute directly in the job step there has been a permission failure. I guess this is that this is because Agent tries to access the command line when it starts the command with RUNAS.
Remotely signed PowerShell script works locally but not via SQL Agent job
I have a Remotely Signed PowerShell script that I am trying to run from a SQL Agent job. The job is configured to use a CmdExec proxy that has the permissions required by the script. The command line is of the format:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy RemoteSigned -File <path_to_script>\Script.ps1 -scriptArgs1 example
The job step fails with the error:
Executed as user: <proxy_user>. <path_to_script>\Script.ps1 : File <path_to_script>\Script.ps1 cannot be loaded. The file <path_to_script>\Script.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 ...
If I log onto the server that hosts the instance and run the same command as the proxy user, it works without issue.
SQL Server Other
2 answers
Sort by: Most helpful
-
Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
2024-08-12T21:34:15.85+00:00 -
Anonymous
2024-08-13T01:39:44.8966667+00:00 Hi @Peter Bishop ,
Thanks for your reaching out and welcome to Microsoft Q&A!
The default execution policy on a Windows client machine is "Restricted". That prevents the running of any scripts.
Changing the execution policy to "RemoteSigned".
Open
Settings → Privacy & Security → For developers
Scroll down to the section PowerShell and click Apply. This will change the execution policy for the scope "CurrentUser" to "RemoteSigned". This change will allow local PowerShell scripts to run without signing.
You might also want to check the properties of the file you are trying to run and ensure the file is not blocked from running.
In addition, please refer to this article, it provides 5 ways to fix PowerShell is Not Digitally Signed Error.
Feel free to share your issues here if you have any concerns!
Best regards,
Lucy Chen
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
https://docs.microsoft.com/en-us/answers/support/email-notifications