Running PSADT in 64 bit Powershell (on 64 bit machines) - multiple ways to solve the issue

Further to my question / discussion about the PSADT Registry functions (Working with Registry keys using PSADT 4.1.x), I've found that my attempt to write to HKLM:\SOFTWARE\CompanyName\SSMS 21\ results in it actually being written to HKLM:\SOFTWARE\WOW6432Node\CompanyName\SSMS 21\.
I have realised that as a result of my Intune deployment command line:

Powershell.exe -ExecutionPolicy Bypass .\Invoke-AppDeployToolkit.ps1 -DeploymentType "Install"

is actually running PowerShell as 32-bit on my 64-bit OS machine - (I understand this is the default)

So, after reading the following (old) discussion:

I have realised that I could solve this by changing the PowerShell.exe path to:

%windir%\sysnative\WindowsPowershell\v1.0\Powershell.exe ....

However...
Alternatively, if put the following PowerShell architecture detection logic at the start of the Invoke-AppDeployToolkit.ps1 script:

# Relaunch in 64-bit PowerShell if running in 32-bit mode
if ($env:PROCESSOR_ARCHITECTURE -ne "AMD64") {
    Write-Output "Re-launching script in 64-bit PowerShell..."
    $scriptPath = $MyInvocation.MyCommand.Definition
    Start-Process -FilePath "$env:SystemRoot\SysNative\WindowsPowerShell\v1.0\powershell.exe" -ArgumentList "-ExecutionPolicy Bypass -File `"$scriptPath`"" -Wait
    exit
}

PowerShell would be relaunched if the Architecture is capable
IMHO The advantage to the above logic addition is the install (and uninstall) command line can be kept shorter (tidier) and the Invoke-AppDeployToolkit.ps1 script can be left to determine the correct OS architecture and relaunch PowerShell if required, therefore the command line would work for both 32-bit and 64-bit (Intel / AMD) architecture.

Question to the floor: Would it be better to leave the Install (and uninstall) command as default and use the logic or is there a valid reason why the detection logic shouldn't be included in the Invoke-AppDeployToolkit.ps1 script?
or for a bit of fun here's a poll:

  • Leave Install (and Uninstall) Command line as default PowerShell.exe - ExecutionPolicy... and add OS detection logic within Invoke-AppDeployToolKit.ps1 script
  • Change Install (and Uninstall) Command line to %windir%\sysnative\WindowsPowershell\v1.0\powershell.exe -ExecutionPolicy and not add OS detection logic within Invoke-AppDeployToolKit.ps1 script
0 voters

You're supposed to just use our exe as we manage this for you.

Ah! OK, I 'think' that might be a change in advice from v3 to v4
I think the Documentation for this may need to be clearer (Maybe by explaining how the exe detects the OS architecture it's run on):

P.S. There are a few layout issues on this page that make it look like you launch the Invoke-AppDeployTookit.exe with Powershell - which can't be right?
One example:

Deploy an application in silent mode with 3010 reboot codes suppressed: powershell Invoke-AppDeployToolkit.exe -DeploymentType Install -DeployMode Silent -SuppressRebootPassThru
I'll report these to the Website GitHub page now

PRs are also welcome if you have the time, we're pretty strapped on resourcing within the team :sweat_smile:

Do not run a simple powershell.exe, run a %WINDIR%\system32\WindowsPowershell\v1.0\Powershell.exe and it works on all plattforms

This does not do what you think it will with Intune as the Intune Management Extension is a 32-bit process. You must use %WINDIR%\sysnative\WindowsPowerShell\v1.0\powershell.exe as others have mentioned above.