简体   繁体   English

Powershell远程签名策略不适用于SQL Agent Job,但在“手动”运行时有效

[英]Powershell remotesigned policy not working with SQL agent Job, but working if run “manually”

I have a SQL 2008 job that does database backups using a Powershell script. 我有一个使用Powershell脚本进行数据库备份的SQL 2008作业。 Each step in the SQL job is "Operating system (CmdExec)" type. SQL作业中的每个步骤都是“操作系统(CmdExec)”类型。 Each step kicks off a powershell script that performs SQL backup and other things. 每个步骤都将启动执行SQL备份和其他操作的Powershell脚本。 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. 如果我将Powershell执行策略设置为“绕过”,则SQL作业将起作用。 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. 但是,如果我从CMD窗口启动脚本,则脚本将正确运行。 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". 服务器是64位的,因此我确保32位和64位Shell的执行策略都设置为“远程签名”。 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). 并且,我将远程服务器UNC路径设置为IE中的受信任Intranet站点(发现Powershell会将本地UNC路径视为http路径,除非在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. 就像我说的那样,如果从CMD窗口中将执行策略设置为远程签名,则手动启动它可以正常运行;如果将执行策略设置为绕过,则在关闭该SQL作业时可以正常运行。 It only fails if it gets kicked off from SQL and the execution policy is set to remotesigned. 仅当它从SQL启动并且执行策略设置为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. 它已经运行了一年,并且Powershell执行策略没有设置为绕过任何问题,但是有人告诉我现在将执行策略设置为remotesigned。 Keeping it at bypass is no longer an option. 使其不再处于旁路状态。

Any thoughts? 有什么想法吗?

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. 您可能必须更改代理作业用户的权限,以允许Powershell脚本按预期运行。

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 为了使某些旧版应用程序能够与Powershell一起使用,我发现自己正在编写小的.bat“引导”脚本,其中仅包含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. 无论如何,这都不是一种创造性,优雅的解决方案,也不是“解决问题”的解决方案,但是,如果该解决方案在CMD上有效,则可以尝试这样做,以使其尽快运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM