从C#运行powershell脚本时出错
我想从powershell触发一个站点设计。它在这里工作,但当我尝试通过c#运行它时,我得到以下错误: 无法将值“param”转换为类型 “Microsoft.Online.SharePoint.PowerShell.SPOSiteDesignPipeBind”。错误: “Guid应包含32位数字和4个破折号 (xxxxxxxx-xxxx-xxxx-xxxx-XXXXXXXXXX) 我已经测试了几个版本的从C#运行powershell脚本时出错,c#,sharepoint,powershell-3.0,C#,Sharepoint,Powershell 3.0,我想从powershell触发一个站点设计。它在这里工作,但当我尝试通过c#运行它时,我得到以下错误: 无法将值“param”转换为类型 “Microsoft.Online.SharePoint.PowerShell.SPOSiteDesignPipeBind”。错误: “Guid应包含32位数字和4个破折号 (xxxxxxxx-xxxx-xxxx-xxxx-XXXXXXXXXX) 我已经测试了几个版本的addScript字符串,但都没有成功。这是我正在尝试运行的代码。它在powershell中
addScript
字符串,但都没有成功。这是我正在尝试运行的代码。它在powershell中运行良好
PowerShellInstance.AddScript(“调用SPOSiteDesign-Identity参数($paramSiteDesignId)-WebUrl参数($paramUrl)”;
PowerShellInstance.AddParameter(“paramSiteDesignId”,“176d2af0-1772-41b2-9ad7-acfceefc8851”);
PowerShellInstance.AddParameter(“paramUrl”https://TenantName.sharepoint.com/sites/TMVTest13");
非常感谢为我指明正确方向的任何帮助。正如您在上看到的,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");```
正如您在上所看到的,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");```
我在C#with Tenant.ApplySiteDesign中找到了一种直接使用C#with Tenant.ApplySiteDesign的方法。效果很好。有关详细信息,请参阅链接。我在C#with Tenant.ApplySiteDesign中找到了一种直接使用C#with Tenant.ApplySiteDesign的方法。效果很好。有关详细信息,请参阅链接。我尝试过这样做,但出现了一个新错误。{无法处理命令,因为缺少一个或多个必需参数:Identity WebUrl。}所以现在看起来所有参数都不在实际的脚本代码中。@Bakkers你能试试我编辑过的答案吗?显然那些
Add
方法返回一个PSCommand
对象,并添加了脚本/参数,但似乎没有触及它们执行的对象。我尝试过这样做,但出现了一个新错误。{无法处理命令,因为缺少一个或多个必需参数:Identity WebUrl。}所以现在看起来所有参数都不在实际的脚本代码中。@Bakkers你能试试我编辑的答案吗?显然那些Add
方法返回一个PSCommand
对象并添加了脚本/参数,但似乎没有触及它们执行的对象。请编辑你的答案并添加更多细节。你的答案是即使您引用的网站宕机或其内容发生更改,您仍应允许其他人解决类似问题。请编辑您的答案并添加更多详细信息。您的答案仍应允许其他人解决类似问题,即使您引用的网站宕机或其内容发生更改。