8

I read this answer: How to Open Powershell from Powershell

start powershell

This opens the base, large resolution PS instance. How do I open PS(x86)?

VSO
  • 11,546
  • 25
  • 99
  • 187
  • What's provoking the question, though? – Bill_Stewart Jun 30 '17 at 14:49
  • @Bill_Stewart I want to build a script that starts my dev tools for me. – VSO Jun 30 '17 at 14:57
  • How does running the x86 version of PowerShell help you do this? What problem are you trying to solve? – Bill_Stewart Jun 30 '17 at 15:42
  • @Bill_Stewart I like the way it looks when I open up 3 instances - one for unit tests, one for running backend, one for running front end build. – VSO Jun 30 '17 at 16:41
  • But why do you need to run the 32-bit version of PowerShell? – Bill_Stewart Jun 30 '17 at 16:50
  • 1
    The bounty description states "none of these actually open the x86 version" - can you upddate the question to clarify exactly what leads to believe this, and exactly what you expect to happen? – Mathias R. Jessen Jul 13 '17 at 17:52
  • @MathiasR.Jessen, can you please update the question explaining why none of these solutions work and what makes you believe they are incorrect? Opening the PS version under SysWOW64 is all PowerShell does when you launch from the start menu. – PSGuy Jul 17 '17 at 20:07
  • @PSGuy I don't know, I'm asking OP – Mathias R. Jessen Jul 17 '17 at 20:13
  • 1
    @VSO, update please? Some of us have asked additional questions in the comments. If you've found a solution, can you please post it for others? – PSGuy Jul 18 '17 at 21:23
  • @PSGuy My PS instance was running with a weird resolution and I misunderstood something. These probably ARE valid answers. I apologize for not answering sooner. – VSO Jul 19 '17 at 13:36

7 Answers7

17
Start-Process $Env:WINDIR\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
Caleb Seelhoff
  • 261
  • 1
  • 8
6

I recommend Caleb's answer. But personally, I have a function in the PowerShell profile that loads on startup and launches a new PowerShell x86 shell when running x86 as this is so commonly required.

Function x86{
    Start-Process $($env:SystemRoot + "\syswow64\WindowsPowerShell\v1.0\powershell.exe")
}

NB: $env:windir and $env:SystemRoot are equivalent here. Maybe not always

G42
  • 9,791
  • 2
  • 19
  • 34
2

For a quick fix I think this solution will help you

start 'C:\Users\(Your-username here)\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell\Windows PowerShell (x86).lnk'

Please note this is just a quick fix.

The following code will Dynamically switch 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"
Chetan Kulkarni
  • 404
  • 4
  • 15
2

You will need the complete path to the x86 Powershell executable. If you are launching it from the command prompt (CMD.EXE), you would use

start "" "%SystemRoot%\SysWOW64\WindowsPowerShell\v1.0\powershell.exe"

If you were starting it from a PowerShell session, you would use

start "" "$env:SystemRoot\SysWOW64\WindowsPowerShell\v1.0\powershell.exe"

or

Start-Process -FilePath "$env:SystemRoot\SysWOW64\WindowsPowerShell\v1.0\powershell.exe"
Jeff Zeitlin
  • 9,773
  • 2
  • 21
  • 33
2

When I last had to run a 32-bit version of PowerShell it was for something specific (there was no 64-bit version of a DLL that I needed to access, reference: View All Certificates On Smart Card). When that was the case I simply executed the needed code as a background job using the -RunAs32 switch for New-Job. Full code that I ended up using can be found in the referenced question, but the general concepts are:

$RunAs32Bit = {

Do some stuff that requires 32-bit

}

#Run the code in 32bit mode if PowerShell isn't already running in 32bit mode
If($env:PROCESSOR_ARCHITECTURE -ne "x86"){
    Write-Warning "Non-32bit architecture detected, collecting certificate information in separate 32bit process."
    $Job = Start-Job $RunAs32Bit -RunAs32
    $SCStore = $Job | Wait-Job | Receive-Job
}Else{
    $SCStore = $RunAs32Bit.Invoke()
}
TheMadTechnician
  • 34,906
  • 3
  • 42
  • 56
  • Thanks, awesome answer, I found it very helpful for manipulation of .NET Framework 32/64 versions configs: https://stackoverflow.com/questions/39925805/writing-to-the-machine-config-file-in-powershell – LordMsz Jun 30 '23 at 10:40
0

Download PSExec

Then, run this in PowerShell: PATH_TO_PSEXEC\psexec.exe -i powershell

rikola
  • 641
  • 7
  • 21
0

The core structure including passing of parameters in either scenario is given below

Param(
    [String] $Param1 =@("Param1"),
    [String] $Param2 =@("Param2")
)
    $ScriptLocation = Split-Path $script:MyInvocation.MyCommand.Path -Parent
    Write-Host $ScriptLocation

$RunAs32Bit = {
    Param(
    [String] $Param1 =@("Param1"),
    [String] $Param2 =@("Param2")
    )
    ...        

    return $Result  
}

#Run the code in 32bit mode if PowerShell isn't already running in 32bit mode
If($env:PROCESSOR_ARCHITECTURE -ne "x86"){
    Write-Warning "Non-32bit architecture detected, processing original request in separate 32bit process."
    $Job = Start-Job $RunAs32Bit -RunAs32 -ArgumentList ($Param1, $Param2, $ScriptLocation)
    $Result = $Job | Wait-Job | Receive-Job
}Else{
    $Result = Invoke-Command -ScriptBlock $RunAs32Bit -ArgumentList ($Param1, $Param2, $ScriptLocation)
}
vikas pachisia
  • 553
  • 5
  • 8