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?
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.
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.
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 .
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.
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
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 #############################################################################
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With