Running PowerShell from PrimalScript

PrimalScript 2007, as many of you know, is configured by default to capture PowerShell output. Output is sent to the Output panel. However, there may be situations where you prefer to launch your script from PrimalScript but have it execute in an actual PowerShell session. You can modify PrimalScript’s PowerShell execution by going to Toos – Options – Environment – Languages and find Windows PowerShell in the languages list. Uncheck “Capture Output” and click OK.  Now when you run a PowerShell script, a new PowerShell window will be launched that will execute your script.

By default, the window will remain open so you can see the results. However, you may run into a problem with the current configuration if you have a PowerShell profile. Specifically, if you have a line in your profile like:

set-location C:\

The current PowerShell language configuration attempts to use your script’s directory as the default location when launching an external PowerShell session. However, if your profile has a line like above, the default location is changed and your script will fail.

The solution is very easy. Edit the PowerShell language options and change the Arguments setting to: -NoLogo -NoExit “&’$File$'”

The Initial Directory setting should be $FileDir$

In the next PrimalScript service build this will be the default. Again, this is only an issue if your profile includes a statement to change location and you want to run your PowerShell scripts in an external PowerShell session.