PowerTip: Launch Console Command Embedded in Powershell Variable

Doctor Scripto

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"



Discussion is closed.

Feedback usabilla icon