{"id":493,"date":"2025-02-20T12:35:00","date_gmt":"2025-02-20T11:35:00","guid":{"rendered":"https:\/\/digitalmaterial.ch\/blog\/?p=493"},"modified":"2025-02-18T07:47:45","modified_gmt":"2025-02-18T06:47:45","slug":"run-win32-apps-from-intune-in-64-bit-powershell","status":"publish","type":"post","link":"https:\/\/digitalmaterial.ch\/blog\/run-win32-apps-from-intune-in-64-bit-powershell\/","title":{"rendered":"Run Win32 Apps from Intune in 64 Bit PowerShell"},"content":{"rendered":"\n<p>As you may know (or have not realised so far) is that all your Win32 apps in Intune are being run in the 32 Bit environment. Usually this is not an issue as most executables elevate themselves into the 64 Bit environment if required. But there are some edge cases, where this is relevant, like creating some entries in the registry.<\/p>\n\n\n\n<p>But let&#8217;s start from the beginning: We usually pack more complex Applications into a Win32 App \/ Intune-Win File. There we pack the executable and usually two PowerShell Files for installation and uninstallation and those a triggered as follows from Intune: <code>powershell.exe -ExecutionPolicy Bypass -WindowStyle hidden -File install.ps1<\/code><\/p>\n\n\n\n<p>As mentioned above, this script is being run in a 32 Bit environment and if you need to create registry items in the <code>HKLM:\\SOFTWARE\\<\/code> node, you will notice, that the items you just added are ending up in the <code>HKLM:\\SOFTWARE\\WOW6432Node<\/code>. Not what you wanted and expected.<\/p>\n\n\n\n<p>We can check that behaviour by adding the following lines of code to our PowerShell script and make sure the output is being saved by Start-Transcript or another solution for logging.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">PowerShell<\/span><span role=\"button\" tabindex=\"0\" data-code=\"Write-Host &quot;checking environment&quot;\nWrite-Host &quot;    PowerShell Version: $($PSVersionTable.PSVersion)&quot;\nWrite-Host &quot;    is 64bit os:      $([Environment]::Is64BitOperatingSystem)&quot;\nWrite-Host &quot;    is 64bit process: $([Environment]::Is64BitProcess)&quot;\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #DCDCAA\">Write-Host<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;checking environment&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">Write-Host<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;    PowerShell Version: <\/span><span style=\"color: #569CD6\">$(<\/span><span style=\"color: #D4D4D4\">$PSVersionTable<\/span><span style=\"color: #DCDCAA\">.PSVersion<\/span><span style=\"color: #569CD6\">)<\/span><span style=\"color: #CE9178\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">Write-Host<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;    is 64bit os:      <\/span><span style=\"color: #569CD6\">$(<\/span><span style=\"color: #D4D4D4\">[<\/span><span style=\"color: #569CD6\">Environment<\/span><span style=\"color: #D4D4D4\">]::Is64BitOperatingSystem<\/span><span style=\"color: #569CD6\">)<\/span><span style=\"color: #CE9178\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">Write-Host<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;    is 64bit process: <\/span><span style=\"color: #569CD6\">$(<\/span><span style=\"color: #D4D4D4\">[<\/span><span style=\"color: #569CD6\">Environment<\/span><span style=\"color: #D4D4D4\">]::Is64BitProcess<\/span><span style=\"color: #569CD6\">)<\/span><span style=\"color: #CE9178\">&quot;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>On a 64 Bit system, this will then return the following output:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">PowerShell<\/span><span role=\"button\" tabindex=\"0\" data-code=\"checking environment\n    PowerShell Version: 5.1.26100.2161\n    is 64bit os:      True\n    is 64bit process: False\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D4D4D4\">checking environment<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    PowerShell Version: <\/span><span style=\"color: #B5CEA8\">5.1<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #B5CEA8\">26100.2161<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    is 64bit os:      True<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    is 64bit <\/span><span style=\"color: #C586C0\">process<\/span><span style=\"color: #D4D4D4\">: False<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>So, what can we do about that? We can simply trigger the 64 Bit PowerShell to run our commands. And if you were wondering, the PowerShell 5 executable is hiding under the following path if you&#8217;re in a 32 Bit environment.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">PowerShell<\/span><span role=\"button\" tabindex=\"0\" data-code=\"&quot;$($env:SystemRoot)\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe&quot;\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #CE9178\">&quot;<\/span><span style=\"color: #569CD6\">$(<\/span><span style=\"color: #9CDCFE\">$env:SystemRoot<\/span><span style=\"color: #569CD6\">)<\/span><span style=\"color: #CE9178\">\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe&quot;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>There are multiple options to solve that issue, and we&#8217;re going to look into the following three:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Pass the cmlets to 64 Bit PowerShell<\/strong><br>We can call the 64Bit PowerShell executable and pass the required commands via the Command parameter.<\/li>\n\n\n\n<li>U<strong>se a dedicated 64 Bit script<\/strong><br>We can use a dedicated Script containing the code to be run in 64 Bit PowerShell<\/li>\n\n\n\n<li><strong>Run the whole file itself<\/strong><br>Or we can call the Install-Script itself in 64 Bit PowerShell<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Pass the cmlets to 64 Bit PowerShell<\/h2>\n\n\n\n<p>This is the simplest variant, but it gets quite messy if you need to run multiple or complex commands. But we just call the 64 Bit PowerShell executable with the <code>Command<\/code> Parameter.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">PowerShell<\/span><span role=\"button\" tabindex=\"0\" data-code=\"C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe -Command { &quot;is 64bit process: $([Environment]::Is64BitProcess)&quot; }\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #D4D4D4\">C:\\Windows\\sysnative\\WindowsPowerShell\\v1.<\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">\\<\/span><span style=\"color: #DCDCAA\">powershell.exe<\/span><span style=\"color: #D4D4D4\"> -Command { <\/span><span style=\"color: #CE9178\">&quot;is 64bit process: <\/span><span style=\"color: #569CD6\">$(<\/span><span style=\"color: #D4D4D4\">[<\/span><span style=\"color: #569CD6\">Environment<\/span><span style=\"color: #D4D4D4\">]::Is64BitProcess<\/span><span style=\"color: #569CD6\">)<\/span><span style=\"color: #CE9178\">&quot;<\/span><span style=\"color: #D4D4D4\"> }<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Use a dedicated 64 Bit script<\/h2>\n\n\n\n<p>Another option is to create a dedicated script containing all the commands that need to be run in 64 Bit PowerShell. And we&#8217;re going to add that script to the Intunewin File we&#8217;re packing.<\/p>\n\n\n\n<p>From the initial Install-Script, we can then run the 64 Bit PowerShell Executable with the <code>File<\/code> Parameter. In the following code, we&#8217;re assuming that the dedicated script is in the same folder as the Install-Script.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">PowerShell<\/span><span role=\"button\" tabindex=\"0\" data-code=\"$PowershellX64Executable = &quot;$($env:SystemRoot)\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe&quot;\n$Arguments = &quot;-File `&quot;$($PSScriptRoot)\\MyCustomScript.ps1`&quot;&quot;\n\n$Process = Start-Process `\n        -FilePath $PowershellX64Executable `\n        -ArgumentList $Arguments `\n        -PassThru `\n        -Wait\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #9CDCFE\">$PowershellX64Executable<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;<\/span><span style=\"color: #569CD6\">$(<\/span><span style=\"color: #9CDCFE\">$env:SystemRoot<\/span><span style=\"color: #569CD6\">)<\/span><span style=\"color: #CE9178\">\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$Arguments<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;-File <\/span><span style=\"color: #D7BA7D\">`&quot;<\/span><span style=\"color: #569CD6\">$(<\/span><span style=\"color: #9CDCFE\">$PSScriptRoot<\/span><span style=\"color: #569CD6\">)<\/span><span style=\"color: #CE9178\">\\MyCustomScript.ps1<\/span><span style=\"color: #D7BA7D\">`&quot;<\/span><span style=\"color: #CE9178\">&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$Process<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #DCDCAA\">Start-Process<\/span><span style=\"color: #D4D4D4\"> `<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        -FilePath <\/span><span style=\"color: #9CDCFE\">$PowershellX64Executable<\/span><span style=\"color: #D4D4D4\"> `<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        -ArgumentList <\/span><span style=\"color: #9CDCFE\">$Arguments<\/span><span style=\"color: #D4D4D4\"> `<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        -PassThru `<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        -Wait<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Run the whole file itself<\/h2>\n\n\n\n<p>The last option is to call the Install-Script  from the Install-Script. But, with some extra steps.<\/p>\n\n\n\n<p>First we check, if we&#8217;re on a 64 Bit OS and if the Process is running in the 32 Bit environment. If this is true, we&#8217;re calling our script in the 64 Bit Environment. And due to above check, we run the following <code>if<\/code> statement only once. Make sure to exit the Script after launching the Process.<\/p>\n\n\n\n<p>Of course, we need to be careful about recursion (to understand recursion, you first have to understand recursion. <a href=\"https:\/\/www.google.com\/search?q=recursion\" target=\"_blank\" rel=\"noreferrer noopener\">You may Google it as well.<\/a>)<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">PowerShell<\/span><span role=\"button\" tabindex=\"0\" data-code=\"if ([Environment]::Is64BitOperatingSystem -eq $true -and [Environment]::Is64BitProcess -eq $false) {\n    $PowershellX64Executable = &quot;$($env:SystemRoot)\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe&quot;\n    $Arguments = &quot;-File `&quot;$($MyInvocation.MyCommand.Definition)`&quot;&quot;\n\n    Write-Host &quot;starting process in 64bit powershell&quot;\n    Write-Host &quot;    using executable '$($PowershellX64Executable)'&quot;\n    Write-Host &quot;    using arguments '$($Arguments)'&quot;\n    Stop-Transcript\n\n    $Process = Start-Process `\n        -FilePath $PowershellX64Executable `\n        -ArgumentList $Arguments `\n        -PassThru `\n        -Wait\n\n    exit $Process.ExitCode\n}\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> ([<\/span><span style=\"color: #569CD6\">Environment<\/span><span style=\"color: #D4D4D4\">]::Is64BitOperatingSystem -eq <\/span><span style=\"color: #569CD6\">$true<\/span><span style=\"color: #D4D4D4\"> -and [<\/span><span style=\"color: #569CD6\">Environment<\/span><span style=\"color: #D4D4D4\">]::Is64BitProcess -eq <\/span><span style=\"color: #569CD6\">$false<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">$PowershellX64Executable<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;<\/span><span style=\"color: #569CD6\">$(<\/span><span style=\"color: #9CDCFE\">$env:SystemRoot<\/span><span style=\"color: #569CD6\">)<\/span><span style=\"color: #CE9178\">\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">$Arguments<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;-File <\/span><span style=\"color: #D7BA7D\">`&quot;<\/span><span style=\"color: #569CD6\">$(<\/span><span style=\"color: #9CDCFE\">$MyInvocation<\/span><span style=\"color: #DCDCAA\">.MyCommand.Definition<\/span><span style=\"color: #569CD6\">)<\/span><span style=\"color: #D7BA7D\">`&quot;<\/span><span style=\"color: #CE9178\">&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">Write-Host<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;starting process in 64bit powershell&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">Write-Host<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;    using executable &#39;<\/span><span style=\"color: #569CD6\">$(<\/span><span style=\"color: #9CDCFE\">$PowershellX64Executable<\/span><span style=\"color: #569CD6\">)<\/span><span style=\"color: #CE9178\">&#39;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">Write-Host<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;    using arguments &#39;<\/span><span style=\"color: #569CD6\">$(<\/span><span style=\"color: #9CDCFE\">$Arguments<\/span><span style=\"color: #569CD6\">)<\/span><span style=\"color: #CE9178\">&#39;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">Stop-Transcript<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">$Process<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #DCDCAA\">Start-Process<\/span><span style=\"color: #D4D4D4\"> `<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        -FilePath <\/span><span style=\"color: #9CDCFE\">$PowershellX64Executable<\/span><span style=\"color: #D4D4D4\"> `<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        -ArgumentList <\/span><span style=\"color: #9CDCFE\">$Arguments<\/span><span style=\"color: #D4D4D4\"> `<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        -PassThru `<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        -Wait<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #C586C0\">exit<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$Process<\/span><span style=\"color: #DCDCAA\">.ExitCode<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>With this option we only require to have one script, if you call the Script in 64 Bit PowerShell already it will run the required commands as expected and if not, it will spawn a new PowerShell Session in 64 Bit. Make sure to add your commands after the if-Statement.<\/p>\n\n\n\n<p>A whole script could look as follows:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#2b2b2b;color:#c7c7c7\">PowerShell<\/span><span role=\"button\" tabindex=\"0\" data-code=\"Write-Host &quot;checking environment&quot;\nWrite-Host &quot;    PowerShell Version: $($PSVersionTable.PSVersion)&quot;\nWrite-Host &quot;    is 64bit os:      $([Environment]::Is64BitOperatingSystem)&quot;\nWrite-Host &quot;    is 64bit process: $([Environment]::Is64BitProcess)&quot;\n\nif ([Environment]::Is64BitOperatingSystem -eq $true -and [Environment]::Is64BitProcess -eq $false) {\n    $PowershellX64Executable = &quot;$($env:SystemRoot)\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe&quot;\n    $Arguments = &quot;-File `&quot;$($MyInvocation.MyCommand.Definition)`&quot;&quot;\n\n    Write-Host &quot;starting process in 64bit powershell&quot;\n    Write-Host &quot;    using executable '$($PowershellX64Executable)'&quot;\n    Write-Host &quot;    using arguments '$($Arguments)'&quot;\n    Stop-Transcript\n\n    $Process = Start-Process `\n        -FilePath $PowershellX64Executable `\n        -ArgumentList $Arguments `\n        -PassThru `\n        -Wait\n\n    exit $Process.ExitCode\n}\n\n# your commands in 64 bit PowerShell\nStart-Process &quot;msiexec.exe&quot; `\n    -ArgumentList '\/i &quot;YourApp.msi&quot; \/qn \/norestart' `\n    -Wait\n\n$registryPath = &quot;HKLM:\\SOFTWARE\\YourApp\\YourNode&quot;\nif ((Test-Path -Path $registryPath ) -eq $false) {\n    New-Item -Path $registryPath \n}\n\nNew-ItemProperty `\n    -Path $registryPath `\n    -Name &quot;YourItem&quot; `\n    -Value &quot;YourValue&quot; `\n    -PropertyType &quot;String&quot;\n    \nexit 0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #DCDCAA\">Write-Host<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;checking environment&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">Write-Host<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;    PowerShell Version: <\/span><span style=\"color: #569CD6\">$(<\/span><span style=\"color: #D4D4D4\">$PSVersionTable<\/span><span style=\"color: #DCDCAA\">.PSVersion<\/span><span style=\"color: #569CD6\">)<\/span><span style=\"color: #CE9178\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">Write-Host<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;    is 64bit os:      <\/span><span style=\"color: #569CD6\">$(<\/span><span style=\"color: #D4D4D4\">[<\/span><span style=\"color: #569CD6\">Environment<\/span><span style=\"color: #D4D4D4\">]::Is64BitOperatingSystem<\/span><span style=\"color: #569CD6\">)<\/span><span style=\"color: #CE9178\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">Write-Host<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;    is 64bit process: <\/span><span style=\"color: #569CD6\">$(<\/span><span style=\"color: #D4D4D4\">[<\/span><span style=\"color: #569CD6\">Environment<\/span><span style=\"color: #D4D4D4\">]::Is64BitProcess<\/span><span style=\"color: #569CD6\">)<\/span><span style=\"color: #CE9178\">&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> ([<\/span><span style=\"color: #569CD6\">Environment<\/span><span style=\"color: #D4D4D4\">]::Is64BitOperatingSystem -eq <\/span><span style=\"color: #569CD6\">$true<\/span><span style=\"color: #D4D4D4\"> -and [<\/span><span style=\"color: #569CD6\">Environment<\/span><span style=\"color: #D4D4D4\">]::Is64BitProcess -eq <\/span><span style=\"color: #569CD6\">$false<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">$PowershellX64Executable<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;<\/span><span style=\"color: #569CD6\">$(<\/span><span style=\"color: #9CDCFE\">$env:SystemRoot<\/span><span style=\"color: #569CD6\">)<\/span><span style=\"color: #CE9178\">\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">$Arguments<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;-File <\/span><span style=\"color: #D7BA7D\">`&quot;<\/span><span style=\"color: #569CD6\">$(<\/span><span style=\"color: #9CDCFE\">$MyInvocation<\/span><span style=\"color: #DCDCAA\">.MyCommand.Definition<\/span><span style=\"color: #569CD6\">)<\/span><span style=\"color: #D7BA7D\">`&quot;<\/span><span style=\"color: #CE9178\">&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">Write-Host<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;starting process in 64bit powershell&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">Write-Host<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;    using executable &#39;<\/span><span style=\"color: #569CD6\">$(<\/span><span style=\"color: #9CDCFE\">$PowershellX64Executable<\/span><span style=\"color: #569CD6\">)<\/span><span style=\"color: #CE9178\">&#39;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">Write-Host<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;    using arguments &#39;<\/span><span style=\"color: #569CD6\">$(<\/span><span style=\"color: #9CDCFE\">$Arguments<\/span><span style=\"color: #569CD6\">)<\/span><span style=\"color: #CE9178\">&#39;&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">Stop-Transcript<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #9CDCFE\">$Process<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #DCDCAA\">Start-Process<\/span><span style=\"color: #D4D4D4\"> `<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        -FilePath <\/span><span style=\"color: #9CDCFE\">$PowershellX64Executable<\/span><span style=\"color: #D4D4D4\"> `<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        -ArgumentList <\/span><span style=\"color: #9CDCFE\">$Arguments<\/span><span style=\"color: #D4D4D4\"> `<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        -PassThru `<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">        -Wait<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #C586C0\">exit<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">$Process<\/span><span style=\"color: #DCDCAA\">.ExitCode<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\"># your commands in 64 bit PowerShell<\/span><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">Start-Process<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&quot;msiexec.exe&quot;<\/span><span style=\"color: #D4D4D4\"> `<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    -ArgumentList <\/span><span style=\"color: #CE9178\">&#39;\/i &quot;YourApp.msi&quot; \/qn \/norestart&#39;<\/span><span style=\"color: #D4D4D4\"> `<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    -Wait<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #9CDCFE\">$registryPath<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #CE9178\">&quot;HKLM:\\SOFTWARE\\YourApp\\YourNode&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">if<\/span><span style=\"color: #D4D4D4\"> ((<\/span><span style=\"color: #DCDCAA\">Test-Path<\/span><span style=\"color: #D4D4D4\"> -Path <\/span><span style=\"color: #9CDCFE\">$registryPath<\/span><span style=\"color: #D4D4D4\"> ) -eq <\/span><span style=\"color: #569CD6\">$false<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><span style=\"color: #DCDCAA\">New-Item<\/span><span style=\"color: #D4D4D4\"> -Path <\/span><span style=\"color: #9CDCFE\">$registryPath<\/span><span style=\"color: #D4D4D4\"> <\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #DCDCAA\">New-ItemProperty<\/span><span style=\"color: #D4D4D4\"> `<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    -Path <\/span><span style=\"color: #9CDCFE\">$registryPath<\/span><span style=\"color: #D4D4D4\"> `<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    -Name <\/span><span style=\"color: #CE9178\">&quot;YourItem&quot;<\/span><span style=\"color: #D4D4D4\"> `<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    -Value <\/span><span style=\"color: #CE9178\">&quot;YourValue&quot;<\/span><span style=\"color: #D4D4D4\"> `<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    -PropertyType <\/span><span style=\"color: #CE9178\">&quot;String&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">exit<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #B5CEA8\">0<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As you may know (or have not realised so far) is that all your Win32 apps in Intune are being run in the 32 Bit environment. Usually this is not an issue as most executables elevate themselves into the 64 Bit environment if required. But there are some edge cases, where this is relevant, like [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":556,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[16,14],"class_list":["post-493","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-endpoint-management","tag-intune","tag-powershell"],"_links":{"self":[{"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/posts\/493","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/comments?post=493"}],"version-history":[{"count":18,"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/posts\/493\/revisions"}],"predecessor-version":[{"id":570,"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/posts\/493\/revisions\/570"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/media\/556"}],"wp:attachment":[{"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/media?parent=493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/categories?post=493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digitalmaterial.ch\/blog\/wp-json\/wp\/v2\/tags?post=493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}