我試圖從一個類執行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();