0

从我的 C# 代码运行 PowerShell 脚本时遇到问题。该脚本包含来自 PowerShell 管理单元的函数VMWare.View.Broker。我通过以下方式做到这一点:

PSSnapInException psEx;
RunspaceConfiguration runConfig = RunspaceConfiguration.Create();
runConfig.AddPSSnapIn("VMWare.View.Broker", out psEx);
using (Runspace runspace = RunspaceFactory.CreateRunspace(runConfig))
{
    runspace.Open();
    using (Pipeline pipeline = runspace.CreatePipeline())
    {
        string scriptContent = ReadScriptFromFile(scriptPath);
        if (!String.IsNullOrEmpty(scriptContent))
        {
            pipeline.Commands.AddScript(scriptContent);
            var results = pipeline.Invoke();
            runspace.Close();
            foreach (var result in results)
            {
                Console.WriteLine(result);
                if(!String.IsNullOrEmpty(result.ToString()))
                    scriptResult += result+"_";
            }
        }
    }
}

当我使用平台目标 x64 运行我的程序时,它工作正常。但是当我尝试使用 x86 执行我的程序时,我得到了以下异常(由于其他依赖项,我需要使用 x86 运行程序):

System.Management.Automation.PSArgumentException: The Windows PowerShell snap-in
 'VMWare.View.Broker' is not installed on this machine.

 at System.Management.Automation.PSSnapInReader.ReadOne(RegistryKey mshSnapInRoot, String mshsnapinId)
4

1 回答 1

0

Vmware 管理单元是 64 位而不是 32 位。答案在错误消息中。您可以尝试找到一个 32 位 Vmware 管理单元并安装它。

于 2014-03-18T16:50:10.747 回答