I am looking for a method in PowerShell to source the environment variables from running a .bat file script into the Env: provider.
Is there an equivalent to twa_env.cmd that will setup the environment for TWS correctly in PowerShell?
I can start a cmd.exe shell, CALL twa_env.cmd, then start PowerShell. That seems to work. What I cannot yet do is to start a PowerShell shell, run twa_env.cmd, and bring the new variable settings back into the PowerShell Env:.
PowerShell can run a
cmd.exe
shell script (batch file), but it (naturally) has to execute it usingcmd.exe
. The problem is that when thecmd.exe
executable closes, the environment variables it sets don't propagate to the calling PowerShell session.The workaround is to "capture" the environment variables set in the
cmd.exe
session and manually propagate them to PowerShell after the batch file finishes. The followingInvoke-CmdScript
PowerShell function can do that for you: