PointerNullException
PointerNullException

Reputation: 199

Powershell: Script to run with x86 powershell/ise

The script i've created uses componets which are only available with the 32 bit version of powershell.

By default windows excutes the script with powershell x64 and it causes several errors.

Is the a way to set an value at the beginning of a script to force windows to use powershellx86 instead of x64?

Example:

using powershell(x86).exe

scriptblock

Thank you

Upvotes: 1

Views: 6844

Answers (2)

Serjx86
Serjx86

Reputation: 530

There is no straightforward way to do it, but there is a way to invoke another instance of Powershell host in x64 host, and that instance may as well be x86. $env:PROCESSOR_ARCHITECTURE will tell you what version of Powershell host you are running.

Just a sketch, use chisel and sand paper to finish.

function Execute-Scriptx86
{
    param(
    [Parameter(Mandatory=$True,Position=1)]
    [string]$ScriptFile
    )

    if($env:PROCESSOR_ARCHITECTURE -eq "AMD64")
    {
        $powershellx86 = $env:SystemRoot + "\syswow64\WindowsPowerShell\v1.0\powershell.exe"
        & $powershellx86 -File $ScriptFile
    }
    else
    {
        & $ScriptFile
    }
}

Upvotes: 1

Fridden
Fridden

Reputation: 189

Couldn't you just start the "powershell(x86).exe" file?

%SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe

/Fredrik

Upvotes: 3

Related Questions