如何从32位cmd.exe启动64位PowerShell?

Mar*_*son 34 powershell cmd

我知道这是一个奇怪的问题,但我被锁定在第三方供应商,它在目标64位Windows Server 2008 R2集群服务器上启动32位cmd.exe.从这里开始,我想启动一个64位的PowerShell窗口并运行一个脚本.

这是我的测试:

powershell.exe "Get-Module -ListAvailable| Where-Object {$_.name -eq 'FailoverClusters'}"

如果我从32位cmd.exe运行它,我什么都没有返回.如果我从64位cmd.exe运行,我得到:

ModuleType Name                      ExportedCommands
---------- ----                      ----------------
Manifest   FailoverClusters          {}
Run Code Online (Sandbox Code Playgroud)

关于如何从32位cmd shell调用64位PowerShell脚本的任何想法?

Jas*_*irk 80

syswow64允许您从64位代码运行32位系统可执行文件.sysnative允许您从32位代码运行64位系统可执行文件.

所以,你需要运行:

%SYSTEMROOT%\ sysnative\WindowsPowerShell\V1.0\powershell.exe

  • @mishrud错了.从32位cmd.exe调用`%systemroot%\ syswow64\windowspowershell\v1.0\powershell.exe`可以获得32位的PowerShell.您可以使用`ls env验证这一点:`32位版本将`PROCESSOR_ARCHITECTURE`显示为`x86`此外,`syswow64`仅包含32位等效的64位DLL和EXE. (13认同)
  • 此答案在Windows 10下不再有效. (10认同)
  • 我有Windows 7企业64位,如果我使用它,我得到"系统找不到指定的路径".因此,运行64位PowerShell的行是这样的:%systemroot%\ syswow64\windowspowershell\v1.0\powershell.exe (5认同)
  • 它适用于Win10,但我注意到tab完成功能不适用于sysnative. (3认同)
  • 请注意,此命令仅在从64位系统上的32位进程运行时才有效。如果您尝试从64位进程运行此文件,它将无法正常工作。系统重定向器仅适用于32位进程。 (2认同)
  • 我使用的是 Windows 10,我遇到了安装 64 位模块的问题。我没有找到“sysnative”目录。所以我尝试使用在路径“C:\Windows\System32\WindowsPowerShell\v1.0”中找到的 Pwershell.exe。能够使用这个exe成功安装64位模块。 (2认同)

Pro*_*eur 13

此脚本将检查您正在运行的powershell版本,如果您在32位运行,将重新启动到64位.当重新启动时,它还将传入原始调用中使用的任何参数.

#############################################################################
#If Powershell is running the 32-bit version on a 64-bit machine, we 
#need to force powershell to run in 64-bit mode .
#############################################################################
if ($env:PROCESSOR_ARCHITEW6432 -eq "AMD64") {
    write-warning "Y'arg Matey, we're off to 64-bit land....."
    if ($myInvocation.Line) {
        &"$env:WINDIR\sysnative\windowspowershell\v1.0\powershell.exe" -NonInteractive -NoProfile $myInvocation.Line
    }else{
        &"$env:WINDIR\sysnative\windowspowershell\v1.0\powershell.exe" -NonInteractive -NoProfile -file "$($myInvocation.InvocationName)" $args
    }
exit $lastexitcode
}


write-host "Main script body"

#############################################################################
#End
#############################################################################    
Run Code Online (Sandbox Code Playgroud)