【问题标题】:Sharepoint execute powershellscriptSharepoint 执行 powershell 脚本
【发布时间】:2012-06-14 09:15:30
【问题描述】:

我需要在特殊用户凭据下从 ListEventReceiver 执行 PowerShell 脚本。我发现Runspace 可以很好地执行脚本,但是如何使安全(代码中没有密码)“运行为”?

管道

string cmdArg = "C:\\Users\\Administrator\\Documents\\userExist.ps1 " + mailstring;
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();

pipeline.Commands.AddScript(cmdArg);
pipeline.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);
Collection<PSObject> results = pipeline.Invoke();
var error = pipeline.Error.ReadToEnd();
runspace.Close();

我了解了安全存储服务,但我认为它仅适用于整个服务、页面或列表,不能用于单一功能?

有人知道如何解决这个问题吗?

【问题讨论】:

  • 您是否有令人信服的理由不只执行 powershell 脚本在 C# 代码中所做的任何事情?您可以在 powershell 中执行的大部分操作都可以直接在 C# 中执行,并且在 C# 中权限提升非常简单。
  • @Servy 已经存在大量的 powershellscripts,所以我更愿意使用它们。
  • 就存储机密而言,web.config connectionStrings 部分为在 Web 应用程序上下文中运行的 SharePoint 代码提供了一个非常方便的选项。它是为连接字符串设计的,但最终它只是一个内置加密的键/值存储。

标签: c# security list sharepoint powershell


【解决方案1】:

关于在另一个身份下运行脚本,你试过RunWithElevatedPrivileges吗?如果这不能解决问题,则可能值得考虑授予应用程序池的帐户足够的权限以完成所需的任务。

【讨论】:

  • 是的,我已经尝试过 RunWithElevatedPrivileges 但没有成功。应用程序池帐户无法在我们的环境中获得该权限。
  • 在我看来,这似乎归结为更通用的“如何以用户 X 身份运行我的代码?”这篇文章解决了这个问题:stackoverflow.com/questions/1168571/…
猜你喜欢
  • 2020-09-16
  • 2021-11-06
  • 2012-09-18
  • 1970-01-01
  • 1970-01-01
  • 2014-01-06
  • 1970-01-01
  • 2011-07-16
  • 2021-09-19
相关资源
最近更新 更多