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

时间:2013-09-27 16:38:52

标签: 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          {}

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

2 个答案:

答案 0 :(得分:77)

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

所以,你需要运行:

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

答案 1 :(得分:12)

This script将检查您正在运行的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
#############################################################################    
相关问题