Summary: Use a variable to launch a Windows PowerShell cmdlet and maintain the value of $LastExitCode.
How can I use Windows PowerShell to launch a variable that contains the path to a console application
while retaining the error code?
Use the & character before the content in question. This example launches Tree.com in System32
by passing in the Environment variable for Windows:
& "$ENV:Windir\system32\tree.com"