[英]Remote Powershell Access Denied
I have a SQL Server database with some tables and a trigger, the trigger would create either FolderA on ServerA or FolderB on ServerB, this is the command I pass in the trigger for ServerA: 我有一个带有一些表和触发器的SQL Server数据库,该触发器将在ServerA上创建FolderA或在ServerB上创建FolderB,这是我在ServerA的触发器中传递的命令:
SET @folder = 'powershell.exe invoke-command -computername ServerA { powershell.exe -NoProfile -ExecutionPolicy Bypass -File C:\FolderScript\FolderA.ps1 "' +@folderName+'" }'
EXEC master.dbo.xp_cmdshell @folder
I have an intermittent issues with it, it will work just fine for couple of days before it stops then I would have to run it manually from PS on ServerA. 我有一个间歇性的问题,它会在停止前几天正常工作,然后我必须从ServerA上的PS手动运行它。
Because it's intermittent, then we can rule out firewall, permissions, PowerShell enable remote. 因为它是间歇性的,所以我们可以排除防火墙,权限,PowerShell启用远程。 I have a web based application (asp.net) that users run from their machines and it connect to the SQL Server database where the trigger is located.
我有一个基于Web的应用程序(asp.net),用户可以在自己的计算机上运行该应用程序,并将其连接到触发器所在的SQL Server数据库。
Is there some sort of sessions that needs to stay open to prevent access denied error? 是否有某种会话需要保持打开状态以防止访问被拒绝错误? I can't think of anything else that might cause this issue?
我想不出其他任何可能导致此问题的原因?
I suspect the issue is with your quoting happening in the command: 我怀疑问题出在您的命令中:
SET @folder = 'powershell.exe -Command "Invoke-Command -ComputerName ServerA { & ''C:\FolderScript\FolderA.ps1'' ' + @folderName + ' }"'
This should be sufficient to resolve your issue. 这应该足以解决您的问题。 You do not need to repeatedly call
powershell.exe
as you can natively call scripts with the call operator ( &
). 您无需重复调用
powershell.exe
因为您可以使用调用运算符( &
)本地调用脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.