Help with Intune running the Invoke-AppDeployToolkit.ps1 script in 64-bit PowerShell

Hello everyone,

In my Invoke-AppDeployToolkit.ps1 script, I have a 64-bit DLL that crashes when I deploy it via Intune because Intune uses 32-bit PowerShell. So, it does not execute correctly when run from a 32-bit PowerShell session on a 64-bit operating system.

I've tried the following code inside PSADT script to check if PowerShell is running in 32-bit and to restart it as a 64-bit process, but it didn't work:

    If([Environment]::Is64BitOperatingSystem){
        Write-ADTLogEntry -Message "Running 32-bit Powershell on 64-bit OS, Restarting as 64-bit Process..." -Severity 2
        $Arguments = "-NoProfile -ExecutionPolicy ByPass -WindowStyle Hidden -File `"" + $MyInvocation.MyCommand.Path + "`""
        $Path = (Join-Path $Env:SystemRoot -ChildPath "\sysnative\WindowsPowerShell\v1.0\powershell.exe")
        Start-Process $Path -ArgumentList $Arguments -Wait
        Write-ADTLogEntry -Message "Finished Running x64 version of PowerShell"
        Exit
    }Else{
        Write-ADTLogEntry -Message "Running 32-bit Powershell on 32-bit OS"
    }
}

I've also found the Invoke-ADTRegSvr32 command and I'm about to try it out. Is there a simpler way to run the entire script in 64-bit?
If anyone has encountered a similar issue or has a simpler solution for running the script in 64-bit PowerShell, I would greatly appreciate your help!

Thank you in advance!

You're supposed to use our executable that we ship along-side the script as it manages this for you and ensures the right PowerShell host is used.

2 Likes

@George, The suggestion provided by @mjr4077au is best practice, so I'd recommend using his advice.

However, for context You may want to have a look at this page: How to Force Intune to Run App Installations in a 64-bit Context for an example why your code is not working.
Your code uses:

If([Environment]::Is64BitOperatingSystem){
...

The OS Architecture is not overly important here, as 32bit Windows PowerShell launches as 32-bit by default on both 32-bit and 64-bit Windows OS's, it's the Process that's important, hence why the example above uses:

If ([Environment]::Is64BitProcess)
{
...

This could allow you to relaunch the PowerShell process in 64-bit

2 Likes

Thank you both for your help! I can confirm that the solution was to run the executable file instead of the PowerShell script in the install command.

@Adrian_Scott
I will definitely keep it in mind for the future. I've made a note of it and will try it out. Much appreciated!

Please feel free to close this one.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.