Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch 64-bit powershell from 32-bit cmd.exe?

Tags:

powershell

cmd

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?

like image 618
Mark Allison Avatar asked Sep 27 '13 16:09

Mark Allison


People also ask

How do I start PowerShell 64-bit?

Run PowerShell using its executable file 0” (or copy and paste the path into the address bar). There, you find the powershell executable on 32-bits. The 64-bit version of PowerShell (the one that 64-bit Windows opens by default) is located under: “C:\Windows\SysWOW64\WindowsPowerShell\v1.

Can you launch PowerShell from CMD?

You actually need to invoke PowerShell from Command Prompt to launch a different PowerShell window. To do so, type or paste powershell start-process powershell -verb runas into Command Prompt, and then hit Enter. A new elevated PowerShell window will appear.

How do I Run a 64-bit CMD EXE?

One way to launch a 64-bit CMD is to just use "My Computer" and double click C:\Windows\System32\cmd.exe . One way to launch a 32-bit CMD is to do the same but double click C:\Windows\SysWOW64\cmd.exe .

How do I Run a PowerShell script from the command exe?

Running a PowerShell script from the Command Prompt If you would like to run a PowerShell script in CMD, you'll need to execute it by calling the PowerShell process with the -File parameter, as shown below: PowerShell -File C:\TEMP\MyNotepadScript. ps1. PowerShell -File C:\TEMP\MyNotepadScript.


2 Answers

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 
like image 181
Jason Shirk Avatar answered Sep 20 '22 13:09

Jason Shirk


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 #############################################################################     
like image 39
ProfessionalAmateur Avatar answered Sep 22 '22 13:09

ProfessionalAmateur