我试图通过将它们嵌入C#代码来运行powershell脚本,以便激活Sharepoint站点上的(.wsp)模板功能。 我的代码如下
Command installCommand = new Command("Install-SPUserSolution");
installCommand.Parameters.Add("identity", "Template.wsp");
installCommand .Parameters .Add ("site", "siteURL");
// create Powershell runspace
Runspace runspace = RunspaceFactory.CreateRunspace();
// open it
runspace.Open()
// create a pipeline and feed it the script text
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(" Add-PsSnapin Microsoft.SharePoint.PowerShell");
pipeline.Commands.Add(installCommand);
//added just for reference since command dosen’t return anything
pipeline.Commands.Add("Out-String");
// execute the script
Collection<PSObject> results = pipeline.Invoke();
//(This part of the code throws error saying Install-SPUserSolution is not a recognized cmdlet,function,script,…)
// close the runspace
runspace.Close();
注意:
我完全不知道自己可能做错了什么。 任何帮助将不胜感激。
答案 0 :(得分:0)
我终于找到了解决问题的方法, 由于我试图在WCF上运行此代码,我不得不这样做 将spadmin帐户添加到托管wcf的应用程序池中, 使用sp.elevatepriviledges委托 和模仿的结果