10

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)?

10
  • What's provoking the question, though? Commented Jun 30, 2017 at 14:49
  • @Bill_Stewart I want to build a script that starts my dev tools for me. Commented Jun 30, 2017 at 14:57
  • How does running the x86 version of PowerShell help you do this? What problem are you trying to solve? Commented Jun 30, 2017 at 15:42
  • 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? Commented Jul 13, 2017 at 17:52
  • 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? Commented Jul 18, 2017 at 21:23

7 Answers 7

17
+50
Start-Process $Env:WINDIR\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

3

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"

Comments

3

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()
}

1 Comment

Thanks, awesome answer, I found it very helpful for manipulation of .NET Framework 32/64 versions configs: stackoverflow.com/questions/39925805/…
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"

Comments

1

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)
}

Comments

0

Download PSExec

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.