Always running as x86 process when packaging as exe

I have this small project:

Import-Module AzureAD

if ([Environment]::Is64BitProcess) {
  "64Bit"
}
else {
  "32Bit"
}

. (Join-Path $PSScriptRoot 'Form1.designer.ps1')

$Form1.ShowDialog()

Form1 is simply an empty form. In Executable Properties the platform is set to x64.

When running this project in Visual Studio 2019 everything is fine. Output is “64Bit” and Import-Module is working as expected.

When packaging this script and running the resulting .exe from the Powershell console I am getting the following result:

Import-Module : Die aktuelle Prozessorarchitektur ist: X86. Für das Modul "C:\Program
Files\WindowsPowerShell\Modules\AzureAD\2.0.2.61\AzureAD.psd1" ist die folgende Prozessorarchitektur erforderlich:
Amd64.
In Zeile:2 Zeichen:1
+ Import-Module -Name AzureAD
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (C:\Program File...61\AzureAD.psd1:String) [Import-Module], Invalid
   OperationException
    + FullyQualifiedErrorId : Modules_InvalidProcessorArchitecture,Microsoft.PowerShell.Commands.ImportModuleCommand

32Bit

Packaging the script in Visual Studio Code produces the same error.

I found that I could package by right clicking on the script in Visual Studio 2019. Then the executable is running as x64 process. But then I am not able to hide the console window which is essential for this project.

How can I fix the problem?

Thank you very much for your help in advance.

Kind regards,
Michael

Hi Adam

Would you mind having a look at this?

Regards,
Michael

On the Executable Properties tab, you can set the Platform to x64.

image

As already mentioned in my initial statement the platform is set to x64.

Oh, sorry. I missed that. This seems like a bug if it’s not setting it correctly. I’ll look into it.

Version 5.3.3 will fix this issue for you.