簡體   English   中英

在VS2010中執行Powershell Invoke時出錯

[英]Error executing Powershell Invoke in VS2010

我正在嘗試從類中執行powershell腳本,但是當我在x86模式下設置平台目標時出現錯誤:

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)).

我有從x86 Powershell文件夾獲得的System.Management.Automation dll,所以我不知道為什么不在x86中工作

如果我將平台目標設置為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();

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

關於這篇文章,在x86的Platform Target下從.NET運行PowerShell時,似乎有某些命令/模塊似乎有問題。 我特別遇到“導入模塊Web管理”的問題,並且會收到與您相同的錯誤。 無論我在哪里獲得System.Management.Automation.dll都沒關系。 另外,使用ILSpy查看dll,兩者“視覺上”看起來都是一樣的。

不幸的是,我無法解決這個問題,也無法找到任何可行的解決方案。 關於這個完全相同或相似類型問題的帖子有幾篇,所有這些都指向在x86目標平台上運行(我相信它可能需要將.NET應用程序神奇地重定向到PowerShell的SySWoW64版本。 這是一個例子與文件系統

雖然我知道這不是一個好的答案,但我相信答案是在x86平台上無法做到這一點。 如果您嘗試使用WebAdministration模塊執行操作並且無法解決此錯誤,則可以嘗試使用Matt Wrock的導入Microsoft.Web.Administration 的解決方案 這似乎是一個可以接受的工作。

最終,我對該項目的解決方案是將框架定位到“任何CPU”並將32位計算機視為“不受支持”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM