繁体   English   中英

从C#运行Powershell脚本错误结束

[英]Running a powershell script from C# ends in error

我想从Powershell触发网站设计。 它在这里有效,但是当我尝试通过c#运行它时,出现此错误:

无法将值“参数”转换为类型“ Microsoft.Online.SharePoint.PowerShell.SPOSiteDesignPipeBind”。 错误:“向导应包含32个数字和4个破折号(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)

我已经测试了addScript字符串的多个版本,但没有一个起作用。 这是我要运行的代码。 而且它在Powershell中运作良好。

PowerShellInstance.AddScript("Invoke-SPOSiteDesign -Identity param($paramSiteDesignId) -WebUrl param($paramUrl)");
PowerShellInstance.AddParameter("paramSiteDesignId", "176d2af0-1772-41b2-9ad7-acfceefc8851");
PowerShellInstance.AddParameter("paramUrl", "https://TenantName.sharepoint.com/sites/TMVTest13");

非常感谢您为我指明正确的方向。

正如您在docs.microsoft.com上看到的那样AddParameter不能通过替换占位符来实现,而是通过将参数/值对作为参数添加到给定命令中来工作。

您的代码可能会导致如下所示:

Invoke-SPOSiteDesign -Identity param($paramSiteDesignId) -WebUrl param($paramUrl) -paramSiteDesignId 176d2af0-1772-41b2-9ad7-acfceefc8851 -paramUrl https://TenantName.sharepoint.com/sites/TMVTest13

根据文档,这应该做您想要的:

PowerShellInstance = PowerShellInstance.AddScript("Invoke-SPOSiteDesign");
PowerShellInstance = PowerShellInstance.AddParameter("Identity", "176d2af0-1772-41b2-9ad7-acfceefc8851");
PowerShellInstance = PowerShellInstance.AddParameter("WebUrl", "https://TenantName.sharepoint.com/sites/TMVTest13");```

我发现使用Tenant.ApplySiteDesign在C#中直接执行此操作的方法。 效果很好,请参见链接以获取更多信息https://laurakokkarinen.com/the-ultimate-guide-to-sharepoint-site-designs-and-site-scripts/#applying-site-designs-programmatically

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM