繁体   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