Intune Win32 App Installation using PowerShell Script

Change your Install and uninstall command line to specifically call for the 64-bit powershell.exe.

Intune Win32 App Installation using PowerShell Script

First off, credit to these people, if you want to read about the subject in details:
https://call4cloud.nl/2021/05/the-sysnative-witch-project/
https://blog.italik.co.uk/running-powershell-scripts-using-intune/

In moving some scripts I've written for SCCM apps using variables like $env:ProgramFiles or writing to the registry, I tried to reuse the same install command line and detection scripts. But on 64-bit systems, leaving the install line as powershell -ExecutionPolicy Bypass -File Install-Script.ps1 will run in the context of a 32-bit cmd console (because Intune's Win32 App runs in 32-bit, as the name suggests), and the dectection script will run in 64-bit from checking the box that you want to run it in 64-bit.

On your 64-bit Windows workstations, if you used $env:ProgramFiles in your install script and also in your detection script, you end up with installs in C:\Program Files (x86) and detection looking in C:\Program Files.

So how do we make sure our script runs in 64-bit? Change your install and uninstall command line to specifically call for the 64-bit powershell.exe.

%windir%\SysNative\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -file Install-Script.ps1

If you want to test this, the SysNative folder alias is only accessible in 32-bit cmd.exe. You can access that in C:\Windows\SysWOW64\cmd.exe

To check what architecture your PoSh/cmd is in:
cmd: echo "%PROCESSOR_ARCHITECTURE%"
PoSh: $env:PROCESSOR_ARCHITECTURE

There are other options other than changing the Install command line, check out the blogs I linked in the beginning!