PowerTip: Launch Console Command Embedded in Powershell Variable


Summary: Use a variable to launch a Windows PowerShell cmdlet and maintain the value of $LastExitCode.

Hey, Scripting Guy! Question How can I use Windows PowerShell to launch a variable that contains the path to a console application
           while retaining the error code?

Hey, Scripting Guy! Answer 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"

  

Comments (0)

Skip to main content