Page 1 of 1

[Solved] session-setup still launches powershell in 32bits

Published: August 4, 2017 - 10:57
by swbsf
Good morning,
I admit it's quite convoluted, so I'm turning to you to see if anyone has any insights :)

My PowerShell script:

Code: Select all

$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference="Continue"
Start-Transcript -path c:\tmp\Win10.log -append

if ([Environment]::Is64BitProcess) {
        echo "64 bit powershell" }
Else { echo "32 bit powershell" }
Stop-Transcript
The end of session-setup :

Code: Select all

        cmd="c:\\Windows\\System32\\WindowsPowershell\\v1.0\\powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File c:\\tmp\\Win10.ps1"
        run(cmd,timeout=7200)
And the logs tell me:

Code: Select all


    **********************
    Début de la transcription Windows Powershell
    Heure de début : 20170804094010
    Nom d'utilisateur : DESKTOP-IJCDS8M\bobby
    Utilisateur runAs : DESKTOP-IJCDS8M\bobby
    Ordinateur : DESKTOP-IJCDS8M (Microsoft Windows NT 10.0.15063.0)
    Application hôte : c:\Windows\System32\WindowsPowershell\v1.0\powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File c:\tmp\Win10.ps1
    ID de processus : 3080
    PSVersion: 5.1.15063.502
    PSEdition: Desktop
    PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.15063.502
    BuildVersion: 10.0.15063.502
    CLRVersion: 4.0.30319.42000
    WSManStackVersion: 3.0
    PSRemotingProtocolVersion: 2.3
    SerializationVersion: 1.1.0.1
    **********************
    Transcription démarrée, le fichier de sortie est c:\tmp\Win10.log
    32 bit powershell
Amazing, isn't it? The application name, with the full path, is correct, and yet it launches the 32-bit version. But the 32-bit version doesn't have half the commands I need. Thanks, Microsoft.

Re: session-setup always launches PowerShell in 32-bit mode

Published: August 4, 2017 - 11:02 AM
by swbsf
The noose is tightening!

Code: Select all

    >>> run(u'c:\\Windows\\System32\\WindowsPowershell\\v1.0\\powershell.exe -Command "[Environment]::Is64BitProcess"')
    <RunOuput returncode :0>
    u'False\r\n'

Re: session-setup always launches PowerShell in 32-bit mode

Published: August 4, 2017 - 11:20
by swbsf
Okay, so I'll do the questions and answers. ;)
The answer was found here: https://stackoverflow.com/a/23395020/3829020
Sneaky little Windows!
To make a long story short, if you look for the process in System32, this directory is virtualized for 32-bit processes (in this case, Python), so you always end up with a 32-bit PowerShell. Therefore, you have to look for it in %SystemRoot%\SysNative.
Phew.

Re: [Solved] session-setup still launches powershell in 32bits

Published: August 4, 2017 - 4:07 PM
by agauvrit
Excellent solution!

We had the same problem when trying to call dism.exe on a package; you need to look at the Sysnative alias to make sure you're calling the correct one.

Alexandre