Always running as x86 process when packaging as exe

I have this small project:

Import-Module AzureAD

if ([Environment]::Is64BitProcess) {
else {

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


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\\AzureAD.psd1" ist die folgende Prozessorarchitektur erforderlich:
In Zeile:2 Zeichen:1
+ Import-Module -Name AzureAD
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (C:\Program File...61\AzureAD.psd1:String) [Import-Module], Invalid
    + FullyQualifiedErrorId : Modules_InvalidProcessorArchitecture,Microsoft.PowerShell.Commands.ImportModuleCommand


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,

Hi Adam

Would you mind having a look at this?


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


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.

Sorry for the necro, but it seems I’m having the exact same issue.
Platform is set to x64 in Visual Studio but I’m getting the same error

Error while import module: System.InvalidOperationException: The current processor architecture is: X86. The module ‘C:\Program Files\WindowsPowerShell\Modules\AzureAD\\AzureAD.psd1’ requires the following architecture: Amd64.

Can you share the other options you have set? I’m mostly wondering if you are setting the PS version to 7 or Windows PS

These are my current executable properties, I’m not using PS 7 at the moment. Would that fix this issue?

I don’t think so. I thought maybe we’d have more a problem with PS7. Let me verify these settings on my end and see if I run into the same thing.

Sorry for the delay here but I tried this and it is packaging as an x64 process for me. My script is just:


The output in the console is:


Can you try to add that to your script to see what the output is?

I get 8 as output as well.
Could it just be something with the Azure-AD module?

Hmmm could be. The process check is actually done by PowerShell and the AzureAD module is just including the ProcessorArchitecture check in it’s module. I did look at the PS source code and this is how they are checking processor architecture. Not with IntPtr.

Import-Module AzureAD

Can you try compiling that and see what you get? I do not get the x86 error if I’m setting the platform to x64.

Created a new Powershell Forms project and input just your lines.
Result is Amd64 in the console output but still the AzureAD module is failing.

Do I need to change anything in the Configuration Manager? It’s currently set to Any CPU (sorry if it’s a dumb question but I’m still kinda new to this)

No, you shouldn’t have to. It seems to be building with the proper architecture so I’m a bit confused as to why this is happening.

Can you zip up what you’ve built and send it to me? You can DM me a link if you’d like.

Do you want the ps1 files or the created .exe file?

The created exe file.

Couldn’t find the DM button, here the link for a small test program that I made.

1 Like

Thanks. That looks fine. Can you also let me know which version of the AD module you have installed on this machine?

PS C:\Users\adamr> get-module activedirectory -list

    Directory: C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Manifest               ActiveDirectory

This is what gets returned.
I do see there are apparently two versions on my system.

PS C:\WINDOWS\system32> get-module azuread -list

Directory: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Binary  AzureAD                             {Add-AzureADApplicationOwner, Get-AzureADApplication, Get-...
Binary  AzureAD                             {Add-AzureADApplicationOwner, Get-AzureADApplication, Get-...