42

I know it's a weird question but I am locked into a third party vendor which launches a 32-bit cmd.exe on a target 64-bit Windows Server 2008 R2 clustered server. From here I want to launch a 64-bit PowerShell window and run a script.

Here's my test:

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

If I run this from a 32-bit cmd.exe I get nothing returned. If I run from a 64-bit cmd.exe I get:

ModuleType Name                      ExportedCommands
---------- ----                      ----------------
Manifest   FailoverClusters          {}

Any ideas on what I can do to invoke a 64-bit powershell script from a 32-bit cmd shell?

2 Answers 2

103

syswow64 lets you run 32 bit system executables from 64 bit code. sysnative lets you run 64 bit system executables from 32 bit code.

So, you need to run:

%SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe
10
  • 6
    I have Windows 7 Enterprise 64-bit and I get "The system cannot find the path specified" if I use this. So the line that works for me to run 64 bit powershell is this: %systemroot%\syswow64\windowspowershell\v1.0\powershell.exe Jul 21, 2014 at 8:40
  • 17
    @mishrud is mistaken. Calling %systemroot%\syswow64\windowspowershell\v1.0\powershell.exe from 32-bit cmd.exe gets you the 32-bit powershell. You can verify this using ls env: The 32-bit version will show PROCESSOR_ARCHITECTURE as x86 Moreover, syswow64 contains only 32-bit equivalents of 64-bit DLLs and EXEs. Sep 25, 2014 at 8:50
  • 3
    It works for me on Win10, but I noticed tab completion doesn't work on sysnative. Aug 5, 2015 at 4:59
  • 2
    Note that this command only works when run from a 32-bit process on a 64-bit system. it will not work if you try to run this from a 64-bit process. The sysnative redirector is only available to 32-bit processes. Jul 12, 2016 at 12:00
  • 2
    I'm using Windows 10, I have faced the issue with installing 64bit module. I do not find "sysnative" direcotry. So i've tried using Pwershell.exe found in the path "C:\Windows\System32\WindowsPowerShell\v1.0". Able to successfully install 64bit module using this exe. Sep 5, 2017 at 11:21
27

This script will check as see what version of powershell you are running and will relaunch itself to 64-bit if you are running in 32-bit. When the relaunch occurs it will also pass in any parameters used in the original call.

#############################################################################
#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
#############################################################################    
3
  • You saved my bacon! I could not execute IIS powershell cmdlets through the config management tool SaltStack's powershell shell, and it turned out it was executing them in 32 bit (!!) and IIS required 64. Appending this to my scripts saved it. Very excellent.
    – Mr.Budris
    Jun 15, 2017 at 14:44
  • Nice that my 11 year old code is still alive. You can upvote it here, too: stackoverflow.com/a/8749393/1133043
    – ggz
    Feb 1, 2021 at 20:13
  • This helped me! I faced the problem when trying to execute a PowerShell script through the azure DevOps PS task. I wanted the script to be executed on the 64-bit instance. The self-hosted agent had two PowerShell instances, 32 and 64 bit, and the DevOps task, whatever I did, ended up using the 32 bit Powershell.
    – Meer
    Dec 22, 2021 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.