【发布时间】: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