2012-12-31 32 views
4

我試圖從一個類執行PowerShell腳本,但是當我在x86的模式下設置的目標平臺,我得到一個錯誤:錯誤執行Powershell的調用在VS2010

Cannot retrieve the dynamic parameters for the cmdlet. Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)). 

我有System.Management。自動化的DLL我從x86文件夾PowerShell的了,所以我不知道爲什麼在86

不工作如果我設定的目標平臺到x64它工作正常

這裏是我的代碼:

RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create(); 

     Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration); 
     runspace.Open(); 

     RunspaceInvoke scriptInvoker = new RunspaceInvoke(runspace); 

     Pipeline pipeline = runspace.CreatePipeline(); 

     //Here's how you add a new script with arguments 
     string fullPath = Path.GetFullPath(@"..\..\Scripts\CreateApplicationPool.ps1"); 
     Command myCommand = new Command(fullPath); 


     myCommand.Parameters.Add("ApplicationPoolName", "example"); 

     pipeline.Commands.Add(myCommand); 

     // Execute PowerShell script 
     Collection<PSObject> results = pipeline.Invoke(); 

回答

3

我意識到這是一箇舊的問題的新帖子...遇到它時,我自己尋找一個解決方案。

關於這篇文章,似乎有某些命令/模塊在x86平臺目標下從.NET運行PowerShell時出現問題。我特別遇到了「導入模塊Web管理」問題,並且會收到與您所做的相同的錯誤。無論我在哪裏獲得System.Management.Automation.dll,都無關緊要。另外,使用ILSpy來查看dll,這兩個「視覺上」看起來都是一樣的。

不幸的是,我無法解決這個問題,也無法找到任何可行的解決方案。在這個完全相同或相似類型的問題上有幾個帖子,並且都指向在x86目標平臺上運行(我相信它可能需要將.NET應用程序的神奇重定向到SySWoW64版本的PowerShell。Here's an example of that with the File System

儘管我知道這不是一個好的答案,但我相信答案是這不能在x86平臺上完成,如果您試圖使用Web管理模塊進行操作並且無法通過此錯誤,則可以嘗試Matt Wrock's solution導入Microsoft.Web.Administration這似乎是一個可以接受的解決方法

最終,我的項目的解決方案是我的目標是框架「任何CPU」,並考慮32位機器爲「UNS upported」。

相關問題