Using PowerShell Core in PrimalScript

Back in May 2016, SAPIEN did a blog post about “Using Bash with PrimalScript 2016“.  In a way, using similar steps, we can setup and use PowerShell Core in PrimalScript 2017 as well.

Keep in mind, due to the fact that PowerShell Core still in it’s early stages, you’ll have modify the console executable path each time you install the updated version of PowerShell Core: “C:\Program Files\PowerShell\x.0.0-xxxx-x“.

Another thing, PowerShell Core still is progressing in its Beta stage. So, SAPIEN won’t support any issues found with PowerShell Core until it reaches RTM status. If you find any issues with “PowerShell Core”, please send them directly to their Github link at:
https://github.com/PowerShell/PowerShell

 

The Setup

By default PrimalScript, will execute the PowerShell script(s) under Windows PowerShell. In order allow execution of PowerShell Core scripts, we need to add the PowerShell Core executable in their list of “Command Window“.

1. From the PrimalScript menu, click on “File“, and scroll-down to “Options“:

PrimalScript_PSC_01

2. Go to “File Groups“, to “Add New” PowerShell Core file groups:

PrimalScript_PSC_02

3. Go to “Command Window“, to add “New” Shell, and the “Rename” the “New Shell” name to “PowerShell Core 64 bit“:

PrimalScript_PSC_03
PrimalScript_PSC_04
PrimalScript_PSC_05

4. After all these changes are done, you’ll be asked to “..restart..” PrimalScript.

PrimalScript_PSC_06

 

Executing the code

Before executing the code, you’ll need to open the PowerShell Core console:

1. From the menu, click on the “View” tab, then click on “Shell“, and under the “Console Window” select “PowerShell Core 64 bit“.

PrimalScript_PSC_08
PrimalScript_PSC_07

Now that the PowerShell Core console is open, anything that you select to execute will go to that active console.

2. To execute the code, proceed to highlight a portion or the whole script.

3. Right-click on the highlighted area, and select “Execute selection in PowerShell“.

PrimalScript_PSC_010

4. As this will not complete executing the code, go to the “Console Window“, then press enter at the cursor line to execute the code manually.

PrimalScript_PSC_011

 

Limitations

Remember, PrimalScript will let you create PowerShell Core script(s), but there are few limitation:

1. Intellisense is meant for Windows PowerShell, so there might be some cmdlet parameters that won’t show.
2. Executing selected code block, at the “Command Window“, you’ll need to press enter to run the code.

The workaround for executing the code automatically, is to execute the following command:
Remove-Module PSReadLine

Now you can create and test your code without any problem.

Please, feel free to give it a try!