我开始在StackExchange DBA上询问这个问题,但认为这可能是更多的Windows Server安全types的问题。
Server 2012 R2上的SQL Server 2016 SP1 + CU。
我正在尝试使用代理用户在SQL代理作业中运行PowerShell步骤,并且在执行任何代码之前遇到SQL尝试执行内务pipe理的问题。
因此,代理用户包含在SQL Agent PowerShell子系统中。 我只需要一步就可以做一个示例工作,来运行“Get-Date”。 工作出错:
Executed as user: Domain\ProxyUser. A job step received an error at line 1 in a PowerShell script. The corresponding line is 'set-executionpolicy RemoteSigned -scope process -Force'. Correct the script and reschedule the job. The error information returned by PowerShell is: 'Access denied '. Process Exit Code -1. The step failed.
MachinePolicy,UserPolicy和LocalMachine都设置在RemoteSigned中,所以它不像是存在范围问题,而且会产生不同的错误。
如果我把代理用户放在机器上的本地pipe理员,问题就消失了,脚本正常运行。 我在系统上的Windows安全日志中看到这个访问:
Object: Object Server: Security Object Type: File Object Name: \Device\ConDrv Object Handle: 0x4 Process Information: Process ID: 0x6350 Process Name: C:\Windows\System32\conhost.exe Requested Operation: Desired Access: DELETE READ_CONTROL WRITE_DAC WRITE_OWNER SYNCHRONIZE ReadData (or ListDirectory) WriteData (or AddFile) AppendData (or AddSubdirectory or CreatePipeInstance) ReadEA WriteEA Execute/Traverse DeleteChild ReadAttributes WriteAttributes Privileges: SeTakeOwnershipPrivilege
它看起来就像四年前@MaddHatter在这个链接上的基本相同的问题:
使用非pipe理代理的SQL代理Powershell作业失败
是唯一的select把这个用户在本地pipe理员? 似乎是一个相当严重的方法来解决这个问题。 我怎样才能最好地定制这些代理用户的权限,以便工作可以运行?
您可以尝试使用Sysinternals进程监视器来查看SQLAgent(或者也许是powershell)进程的情况:
https://technet.microsoft.com/en-us/sysinternals/processmonitor.aspx
有了这个工具,你将能够看到“访问被拒绝”来自哪里。
另一个select是使用“操作系统(CmdExec)”步骤而不是PowerShell,并调用PowerShell脚本,如下所示:
powershell.exe -File "C:\Path\To\File.ps"