FlintSable
2/12/2011 - 7:37 AM

A simple solution for executing 64-bit PowerShell commands from 32-bit PowerShell without using PS Remoting or requiring administrative priv

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
    }
}