Powershell remotesigned policy not working with SQL agent Job, but working if run "manually"

3.2k views Asked by At

I have a SQL 2008 job that does database backups using a Powershell script. Each step in the SQL job is "Operating system (CmdExec)" type. Each step kicks off a powershell script that performs SQL backup and other things. That script lives on a remote server, so that if we need to make changes, we only have to make them once.

If I set the Powershell execution policy to "Bypass", the SQL job works. But if I set it to "remote signed", it fails saying that the execution policy is not set correctly. However, If I kick off the script from the CMD window, it runs correctly. The server is 64 bit, so I have made sure that both the 32 bit and 64 bit shells have their execution policy set to "remotesigned". And, I have the remote server UNC path set as a trusted intranet site in IE (found that Powershell treats local UNC paths like http paths, unless that is set in IE).

Like I said, it runs correctly I manually kick if off from the CMD window with the execution policy set to remote signed, and it works if the SQL job kicks if off if the execution policy is set to bypass. It only fails if it gets kicked off from SQL and the execution policy is set to remotesigned.

It’s been running for a year without an issue with the Powershell execution policy set to bypass, but I’m being told to set that execution policy to remotesigned now. Keeping it at bypass is no longer an option.

Any thoughts?

2

There are 2 answers

2
Jimbo On BEST ANSWER

Sounds like the credentials under which the job is run is different from your login credentials.

You may have to change the permissions for the agent job user to allow the powershell script to run as expected.

0
SpellingD On

In order to make some legacy applications play with Powershell, I find myself writing small .bat "bootstrap" scripts that just contain something like powershell.exe C:\Scripts\MyScript.ps1

Not a creative, elegant, or "solve the problem" solution by any means, but if it works from CMD then you could try this just to get it working ASAP.