编译为32位或64位时PowerShell之间的结果不同 [英] Different result between PowerShell when compiled as 32 or 64 bit

查看:111
本文介绍了编译为32位或64位时PowerShell之间的结果不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下C#代码段在编译为32位与64位(平台目标为x86与任何CPU或项目的Visual Studio属性中的X64)时显示不同的结果。 代码已在Server 2008 R2(显然是64位)环境中运行。

The following C# code snippet shows different result when it is compiled as 32 bit vs. 64 bit (Platform target as x86 vs. Any CPU or X64 in Visual Studio Properties of the project).  The code has been run on Server 2008 R2 (obviously 64 bit) environment.

您可以在下面找到完整的错误消息,但基本上它会抱怨""Get-WindowsFeature"这个术语不是被识别为cmdlet,函数,脚本文件或可操作程序的名称"。

You can find the full error message below but basically it complains "The term 'Get-WindowsFeature' is not recognized as the name of a cmdlet, function, script file, or operable program".

如果相同的代码被编译为64位(或任何CPU),运行完全正常并给我从Get-WindowsFeature PowerShell命令返回所需的结果。

if the same code get compiled as 64 bit (or Any CPU), run perfectly fine and gives me the desired result back from Get-WindowsFeature PowerShell command.

如果这是由Microsoft引起的错误或我的无知,我不知道但是我想在32位和64位之间看到相同的结果或者从C#代码检查已安装的Windows功能的不同方法。

I don't if this is bug caused by Microsoft or my ignorance but I want to see a same result between 32 and 64 bit, or differnt approach to check installed Windows Feature from C# code.

========================== ==================

============================================

            ; Runspace runspace = RunspaceFactory.CreateRunspace();

            runspace.Open();

            Pipeline pipeline = runspace.CreatePipeline();

            pipeline.Commands.AddScript(" Import-Module ServerManager; Get-WindowsFeature Application-Server");

            Runspace runspace = RunspaceFactory.CreateRunspace();
            runspace.Open();
            Pipeline pipeline = runspace.CreatePipeline();
            pipeline.Commands.AddScript("Import-Module ServerManager; Get-WindowsFeature Application-Server");

          ;&NBSP;&NBSP;收集和LT; PSObject> results = new Collection< PSObject>();

            Collection<PSObject> results = new Collection<PSObject>();

           试试
            {

                results = pipeline.Invoke();

            }

            try
            {
                results = pipeline.Invoke();
            }

...

======================== ====================

============================================

 

是"System.Management" .Automation.CommandNotFoundException:术语"Get-WindowsFeature"未被识别为cmdlet,函数,脚本文件或可操作程序的名称。检查名称的拼写,或者如果包含路径,请验证路径
是否正确,然后重试。

  在System.Management.Automation.CommandDiscovery.LookupCommandInfo(String commandName,CommandOrigin commandOrigin)

  在System.Management.Automation.CommandDiscovery.LookupCommandProcessor(String commandName,CommandOrigin commandOrigin,Nullable`1 useLocalScope)

  在System.Management.Automation.CommandFactory._CreateCommand(String commandName,CommandOrigin commandOrigin,Nullable`1 useLocalScope)

   at System.Management.Automation.ExecutionContext.CreateCommand(String command)

  在System.Management.Automation.CommandNode.CreateCommandProcessor(Int32& index,ExecutionContext context)

  在System.Management.Automation.CommandNode.AddToPipeline(PipelineProcessor管道,ExecutionContext上下文)

   at System.Management.Automation.PipelineNode.Execute(Array input,Pipe outputPipe,ArrayList& resultList,ExecutionContext context)

   at System.Management.Automation.StatementListNode.ExecuteStatement(ParseTreeNode statement,Array input,Pipe outputPipe,ArrayList& resultList,ExecutionContext context"。

is "System.Management.Automation.CommandNotFoundException: The term 'Get-WindowsFeature' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
   at System.Management.Automation.CommandDiscovery.LookupCommandInfo(String commandName, CommandOrigin commandOrigin)
   at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(String commandName, CommandOrigin commandOrigin, Nullable`1 useLocalScope)
   at System.Management.Automation.CommandFactory._CreateCommand(String commandName, CommandOrigin commandOrigin, Nullable`1 useLocalScope)
   at System.Management.Automation.ExecutionContext.CreateCommand(String command)
   at System.Management.Automation.CommandNode.CreateCommandProcessor(Int32& index, ExecutionContext context)
   at System.Management.Automation.CommandNode.AddToPipeline(PipelineProcessor pipeline, ExecutionContext context)
   at System.Management.Automation.PipelineNode.Execute(Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context)
   at System.Management.Automation.StatementListNode.ExecuteStatement(ParseTreeNode statement, Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context".

 

推荐答案

 

 

Hi,

 

如果我们将应用程序编译为x64或任何CPU,托管应用程序将在64位操作系统下以64位进程运行。

Managed application will run as 64bit process under 64bit OS if we compile the application as x64 or Any CPU.

 

请你启动x86版本的power shell提示符,并输入命令:" Get-Module -ListAvailable "
检查
ServerManager 可用。


这篇关于编译为32位或64位时PowerShell之间的结果不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆