簡體   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