{"id":2771,"date":"2018-02-13T12:53:09","date_gmt":"2018-02-13T11:53:09","guid":{"rendered":"https:\/\/www.lieben.nu\/liebensraum\/?p=2771"},"modified":"2018-02-13T12:53:09","modified_gmt":"2018-02-13T11:53:09","slug":"restarting-a-x86-powershell-process-as-x64-automatically","status":"publish","type":"post","link":"https:\/\/lieben.nu\/liebensraum\/2018\/02\/restarting-a-x86-powershell-process-as-x64-automatically\/","title":{"rendered":"Restarting a x86 Powershell Process as x64 automatically"},"content":{"rendered":"<p><span style=\"color: #ff0000;\">2\/27\/2019 update:<\/span> <a href=\"https:\/\/docs.microsoft.com\/en-us\/intune\/intune-management-extension\" target=\"_blank\" rel=\"noopener noreferrer\">intune now supports starting your scripts as 64 bit!<\/a><\/p>\n<p>Let&#8217;s say something (like Intune) starts your Powershell script in 32 bit and you really need commands that only 64 bit Powershell has&#8230;.<\/p>\n<pre><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\n\n#Restart self in x64\nIf (!(&#x5B;Environment]::Is64BitProcess)){\n    if(&#x5B;Environment]::Is64BitOperatingSystem){\n        Write-Output &quot;Running 32 bit Powershell on 64 bit OS, restarting as 64 bit process...&quot;\n        $arguments = &quot;-NoProfile -ExecutionPolicy ByPass -WindowStyle Hidden -File `&quot;&quot; + $myinvocation.mycommand.definition + &quot;`&quot;&quot;\n        $path = (Join-Path $Env:SystemRoot -ChildPath &quot;\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe&quot;)\n        Start-Process $path -ArgumentList $arguments -wait\n        Write-Output &quot;finished x64 version of PS&quot;\n        Exit\n    }else{\n        Write-Output &quot;Running 32 bit Powershell on 32 bit OS&quot;\n    }\n}\n<\/pre>\n<p>With the above at the top of your script, it&#8217;ll automatically restart itself if needed \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2\/27\/2019 update: intune now supports starting your scripts as 64 bit! Let&#8217;s say something (like Intune) starts your Powershell script in 32 bit and you really need commands that only 64 bit Powershell has&#8230;. #Restart self in x64 If (!(&#x5B;Environment]::Is64BitProcess)){ if(&#x5B;Environment]::Is64BitOperatingSystem){ Write-Output &quot;Running 32 bit Powershell on 64 bit OS, restarting as 64 bit process&#8230;&quot; &hellip; <a href=\"https:\/\/lieben.nu\/liebensraum\/2018\/02\/restarting-a-x86-powershell-process-as-x64-automatically\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Restarting a x86 Powershell Process as x64 automatically<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[22,39],"tags":[],"class_list":["post-2771","post","type-post","status-publish","format-standard","hentry","category-intune","category-powershell"],"_links":{"self":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/2771","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/comments?post=2771"}],"version-history":[{"count":0,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/2771\/revisions"}],"wp:attachment":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/media?parent=2771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/categories?post=2771"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/tags?post=2771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}