I am trying to execute a powershell script from a class but I am getting an error when I set the platform target in x86 mode:
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)).
I have the System.Management.Automation dll that I got from the x86 Powershell folder, so I don't get why is not working in x86
If I set the platform target to x64 it works ok
Here is my code:
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();