Created
February 13, 2025 17:48
-
-
Save jschlackman/c24d8f538696bf5f7a6a876654c5bdae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Run a PowerShell command in the 64-bit host. | |
.DESCRIPTION | |
When called from a 32-bit host executable, the specified command block will be run using the 64-bit Powershell host. | |
If called from a 64-bit host, the command is simply run in the current host. | |
.PARAMETER CommandBlock | |
Command block to execute. | |
#> | |
function Run-Ps64 { | |
param ( | |
[Parameter(Mandatory)] [ScriptBlock] $CommandBlock | |
) | |
# Check we are running in 32-bit | |
If ($env:PROCESSOR_ARCHITECTURE -eq 'x86') { | |
# Check 64-bit is available | |
If ($env:PROCESSOR_ARCHITEW6432) { | |
& "$env:SystemRoot\sysnative\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -WindowStyle Hidden -NoProfile -NonInteractive -Command $CommandBlock | |
} Else { | |
Write-Error -Message 'OS is 32-bit only. 64-bit subsystem not available' -Category InvalidOperation | |
} | |
} Else { | |
# Already running 64-bit, execute command natively | |
& $CommandBlock | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment