我正在尝试从一个类中执行一个 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();