0
我试图通过将它们嵌入到C#代码中来运行PowerShell脚本来激活Sharepoint站点上的(.wsp)模板功能。 我的代码如下在c#中的嵌入式PowerShell脚本Install-SPUserSolution没有识别
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();
注:
- 我曾尝试将整个命令作为一个剧本,但我得到了 同样的错误。
- 我已经尝试了SharePoint管理shell 命令提示符下的脚本,它在那里完美工作。
- 我在WCF的库类中使用上述 代码。
- 我在Visual Studio中的每个 子项目的所有平台都设置为“ANY CPU”,并且我使用的是 .net framework 3.5。
- 我还检查了管理shell中的帮助选项 ,并且命令“Install-SPUserSolution”确实是 作为Microsoft.Sharepoint.Powershell的cmdlet存在。
- 我正在使用 客户端对象模型(COM)来完成我的任务,因此不能使用C# 代码来激活功能,因为COM不支持它。
我完全不知道我可能会做错什么。 任何帮助将不胜感激。