Sharepoint执行powershell脚本

时间:2012-06-11 12:58:36

标签: c# security list sharepoint powershell

我需要在特殊用户凭据下从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();

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

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

1 个答案:

答案 0 :(得分:0)

关于在其他身份下运行脚本,您是否尝试过RunWithElevatedPrivileges?如果这不起作用,可能值得考虑授予应用程序池的帐户足够的permisisons来完成所需的任务。