Skip to content

Instantly share code, notes, and snippets.

@jstangroome
Created February 12, 2011 07:37
Show Gist options
  • Save jstangroome/823580 to your computer and use it in GitHub Desktop.
Save jstangroome/823580 to your computer and use it in GitHub Desktop.
A simple solution for executing 64-bit PowerShell commands from 32-bit PowerShell without using PS Remoting or requiring administrative privileges
function Invoke-OSArchitectureCommand (
[Parameter(Mandatory=$true)]
[ScriptBlock]
$ScriptBlock,
$ArgumentList
) {
if ($PSHOME -match '\\syswow64\\') {
$PowerShellx64 = $PSHOME -replace '\\syswow64\\','\sysnative\' | Join-Path -ChildPath powershell.exe
if (-not ($PowerShellx64 | Test-Path)) { throw 'Install Microsoft hotfix KB942589.' }
& $PowerShellx64 -nologo -executionpolicy (Get-ExecutionPolicy) -command $ScriptBlock -args $ArgumentList
} else {
Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList $ArgumentList
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment