{"id":14305,"date":"2018-01-17T05:00:03","date_gmt":"2018-01-17T13:00:03","guid":{"rendered":"https:\/\/www.sapien.com\/blog\/?p=14305"},"modified":"2018-07-13T12:31:29","modified_gmt":"2018-07-13T19:31:29","slug":"sapien-tools-how-to-work-with-powershell-core","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2018\/01\/17\/sapien-tools-how-to-work-with-powershell-core\/","title":{"rendered":"SAPIEN Tools &#8211; How-To Work with PowerShell Core in PrimalScript"},"content":{"rendered":"<p>Now that <strong>PowerShell Core 6.0.0<\/strong> has reached the <strong>GA<\/strong> (<em>Generally Available<\/em>) status, you can start developing scripts using <strong>PrimalScript<\/strong>.<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_01_2018-01-16_9-40-55.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"HowToPSCore_01_2018-01-16_9-40-55\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_01_2018-01-16_9-40-55_thumb.jpg\" alt=\"HowToPSCore_01_2018-01-16_9-40-55\" width=\"244\" height=\"70\" border=\"0\" \/><\/a><\/p>\n<p>Yes, in this product look under &#8220;<strong>File | Options<\/strong>&#8220;, in the &#8220;<strong>Environment<\/strong>&#8221; section you&#8217;ll find the &#8220;<strong>Window Command<\/strong>&#8221; area. Here, PowerShell Core shell can be added manually.\u00a0 Also, if you\u2019re using <strong>Windows 10 Build 16299<\/strong> (<em>or higher<\/em>) with <strong>WSL<\/strong> (<em>Windows Subsystem for Linux<\/em>), your system can also\u00a0be setup to run both &#8220;<strong>Bash<\/strong>&#8221; and &#8220;<strong>Bash with PowerShell Core<\/strong>&#8220;.<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_01a_2018-01-16_9-40-55.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"HowToPSCore_01a_2018-01-16_9-40-55\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_01a_2018-01-16_9-40-55_thumb.jpg\" alt=\"HowToPSCore_01a_2018-01-16_9-40-55\" width=\"484\" height=\"334\" border=\"0\" \/><\/a><\/p>\n<p>Let&#8217;s think about this for a minute. Although our SAPIEN Products are meant to be used in Windows Systems, having <strong>WSL<\/strong> installed will give you the ability to build and test PowerShell Core scripts cross-platform without leaving Windows.<\/p>\n<p>Take a moment to look at the existing blog post:<br \/>\n<a href=\"https:\/\/www.sapien.com\/blog\/2017\/09\/15\/using-powershell-core-in-primalscript\/\">https:\/\/www.sapien.com\/blog\/2017\/09\/15\/using-powershell-core-in-primalscript\/<\/a><\/p>\n<p>For more information about WSL (Windows Subsystem for Linux) click the following link:<br \/>\n<a href=\"https:\/\/blogs.msdn.microsoft.com\/commandline\/\">https:\/\/blogs.msdn.microsoft.com\/commandline\/<\/a><\/p>\n<p>&nbsp;<\/p>\n<h3>Setting up PowerShell Core in PrimalScript<\/h3>\n<p><em>Note: The instructions below are demonstrated in our short video <a href=\"https:\/\/www.youtube.com\/watch?v=y7dKwFTS39I\" target=\"_blank\" rel=\"noopener\">PrimalScript &#8211; Command Window Option<\/a><\/em><\/p>\n<p>The following steps will properly setup PowerShell Core in PrimalScript:<\/p>\n<p>1. Under the &#8220;<strong>File<\/strong>&#8221; menu, go to &#8220;<strong>Options<\/strong>&#8220;.<br \/>\n2. In the &#8220;<strong>Environment<\/strong>&#8221; section, click on &#8220;<strong>Command <strong>Window<\/strong><\/strong>&#8220;.<br \/>\n3. Add a new shell by clicking on the &#8220;<strong>New<\/strong>&#8221; button. This will add a new line to be changed.<\/p>\n<p><em>*Note: Keep in mind, this could be any type of console shell, such as: Python, Ruby, Bash.<\/em><\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_02_2018-01-16_9-40-55.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"HowToPSCore_02_2018-01-16_9-40-55\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_02_2018-01-16_9-40-55_thumb.jpg\" alt=\"HowToPSCore_02_2018-01-16_9-40-55\" width=\"536\" height=\"221\" border=\"0\" \/><\/a><\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_03_2018-01-16_9-40-55.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"HowToPSCore_03_2018-01-16_9-40-55\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_03_2018-01-16_9-40-55_thumb.jpg\" alt=\"HowToPSCore_03_2018-01-16_9-40-55\" width=\"535\" height=\"331\" border=\"0\" \/><\/a><\/p>\n<p>Now, we add PowerShell Core to the &#8220;<strong>Command Window<\/strong>&#8221; list. In the \u201c<strong>New Shell<\/strong>\u201d line, do the following:<\/p>\n<p>A. Double-Click on the \u201c<strong>New Shell<\/strong>\u201d line, and it will allow you to search for the shell executable,<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_04_2018-01-16_9-40-55.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"HowToPSCore_04_2018-01-16_9-40-55\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_04_2018-01-16_9-40-55_thumb.jpg\" alt=\"HowToPSCore_04_2018-01-16_9-40-55\" width=\"542\" height=\"329\" border=\"0\" \/><\/a><\/p>\n<p>Or, simply type the following line:<\/p>\n<p>&#8220;<strong>C:\\Program Files\\PowerShell\\6.0.0\\pwsh.exe -noexit -Command Remove-Module PSReadline -ErrorAction Ignore<\/strong>&#8221;<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_06_2018-01-16_9-40-55.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"HowToPSCore_06_2018-01-16_9-40-55\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_06_2018-01-16_9-40-55_thumb.jpg\" alt=\"HowToPSCore_06_2018-01-16_9-40-55\" width=\"536\" height=\"268\" border=\"0\" \/><\/a><\/p>\n<p>B. Now, click the \u201c<strong>Rename<\/strong>\u201d button to change the \u201c<strong>Shell Name<\/strong>\u201d field from \u201c<strong>New Shell<\/strong>\u201d to &#8220;<strong>PowerShell Core 64bit<\/strong>&#8220;:<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_05_2018-01-16_9-40-55.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"HowToPSCore_05_2018-01-16_9-40-55\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_05_2018-01-16_9-40-55_thumb.jpg\" alt=\"HowToPSCore_05_2018-01-16_9-40-55\" width=\"538\" height=\"267\" border=\"0\" \/><\/a><\/p>\n<p>C. To complete the change, click the \u201c<strong>OK<\/strong>\u201d button and restart <strong>PrimalScript<\/strong>.<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_07_2018-01-16_9-40-55.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"HowToPSCore_07_2018-01-16_9-40-55\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_07_2018-01-16_9-40-55_thumb.png\" alt=\"HowToPSCore_07_2018-01-16_9-40-55\" width=\"538\" height=\"269\" border=\"0\" \/><\/a><\/p>\n<p>To verify the shell has been added to the \u201c<strong>Console Window<\/strong>\u201d list, go to \u201c<strong>View<\/strong>\u201d and click on the \u201c<strong>Shell<\/strong>\u201d option, then click the arrow-down to view the list.<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_08_2018-01-16_9-40-55.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"HowToPSCore_08_2018-01-16_9-40-55\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_08_2018-01-16_9-40-55_thumb.jpg\" alt=\"HowToPSCore_08_2018-01-16_9-40-55\" width=\"556\" height=\"121\" border=\"0\" \/><\/a><\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_09_2018-01-16_9-40-55.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"HowToPSCore_09_2018-01-16_9-40-55\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_09_2018-01-16_9-40-55_thumb.jpg\" alt=\"HowToPSCore_09_2018-01-16_9-40-55\" width=\"555\" height=\"298\" border=\"0\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3>Make PowerShell Core the Active Console Window<\/h3>\n<p>To activate the added shell, look for the &#8220;<strong>Console Window<\/strong>&#8221; panel and click on the pull-down list of available shells.<\/p>\n<p>Proceed to select &#8220;<strong>PowerShell Core 64bit<\/strong>&#8221; shell and it will become active in<strong> PrimalScript<\/strong>. Then, type \u201c<strong><span style=\"color: #0000ff;\">$PSVersionTable<\/span><\/strong>\u201d to check that the PowerShell version is PowerShell Core 6.0.0.<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_10_2018-01-16_9-40-55.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"HowToPSCore_10_2018-01-16_9-40-55\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_10_2018-01-16_9-40-55_thumb.jpg\" alt=\"HowToPSCore_10_2018-01-16_9-40-55\" width=\"555\" height=\"305\" border=\"0\" \/><\/a><\/p>\n<p>If there is any need to reset the console, this can be done by right-clicking on the shell and selecting\u00a0 &#8220;<strong>Reset<\/strong>&#8220;.<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_12_2018-01-16_9-40-55.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"HowToPSCore_12_2018-01-16_9-40-55\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_12_2018-01-16_9-40-55_thumb.jpg\" alt=\"HowToPSCore_12_2018-01-16_9-40-55\" width=\"561\" height=\"141\" border=\"0\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h3>Testing your PowerShell Core Scripts<\/h3>\n<p>There are a couple of ways to test your script(s):<\/p>\n<p>1. Just highlight and select a few lines of the code, then right-click and select &#8220;<strong>Execute selection in PowerShell<\/strong>&#8220;.<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_13_2018-01-16_9-40-55.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"HowToPSCore_13_2018-01-16_9-40-55\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_13_2018-01-16_9-40-55_thumb.jpg\" alt=\"HowToPSCore_13_2018-01-16_9-40-55\" width=\"560\" height=\"331\" border=\"0\" \/><\/a><\/p>\n<p>2. Or, to execute the whole script, from the &#8220;<strong>Home<\/strong>&#8221; menu click on the &#8220;<strong>Script Run &#8211; Run<\/strong>&#8220;<strong>*<\/strong> button, then select either &#8220;<strong>Run in Shell<\/strong>&#8221; or &#8220;<strong>Run Selection in Shell<\/strong>&#8220;.<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_13a_2018-01-16_9-40-55.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"HowToPSCore_13a_2018-01-16_9-40-55\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_13a_2018-01-16_9-40-55_thumb.jpg\" alt=\"HowToPSCore_13a_2018-01-16_9-40-55\" width=\"569\" height=\"334\" border=\"0\" \/><\/a><\/p>\n<p>The script will run under the active console whether it is PowerShell Core or any other shell.<\/p>\n<p><em>*Note: If you select to just &#8220;<strong>Run<\/strong>&#8221; the script, it will think you are executing a script for non-Powershell Core.\u00a0 This may give an error, but depends on how the script was built.<\/em><\/p>\n<p>&nbsp;<\/p>\n<h3>Some Caveats<\/h3>\n<p>Testing PowerShell Core scripts is doable! But, here\u2019s the catch: PowerShell and PowerShell Core share the same core modules with slight differences, such as a few parameters changed and\/or a very few non-supported cmdlets in PowerShell Core (for example: <strong><span style=\"color: #0000ff;\">Out-GridView<\/span><\/strong>).<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_14_2018-01-16_9-40-55.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"HowToPSCore_14_2018-01-16_9-40-55\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2018\/01\/HowToPSCore_14_2018-01-16_9-40-55_thumb.jpg\" alt=\"HowToPSCore_14_2018-01-16_9-40-55\" width=\"578\" height=\"305\" border=\"0\" \/><\/a><\/p>\n<p>So, when using <strong>PrimalScript<\/strong> to develop PowerShell Core, test your scripts using the proper \u201c<strong>Run Shell<\/strong>\u201d option. At the same time, understand the difference between the two versions of PowerShell.<\/p>\n<p>&nbsp;<\/p>\n<h3>Upcoming Improvements<\/h3>\n<p><strong><em>SAPIEN Technologies, Inc.<\/em><\/strong> is dedicated to providing the best scripting technology tools for the IT and DevOP professionals.<\/p>\n<p>Stay tuned for more!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Now that PowerShell Core 6.0.0 has reached the GA (Generally Available) status, you can start developing scripts using PrimalScript. Yes, in this product look under &#8220;File | Options&#8220;, in the &#8220;Environment&#8221; section you&#8217;ll find the &#8220;Window Command&#8221; area. Here, PowerShell Core shell can be added manually.\u00a0 Also, if you\u2019re using Windows 10 Build 16299 (or [&hellip;]<\/p>\n","protected":false},"author":47,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2,1143,410],"tags":[],"class_list":["post-14305","post","type-post","status-publish","format-standard","hentry","category-general","category-powershell","category-primalscript-software-news"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/14305","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/47"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=14305"}],"version-history":[{"count":13,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/14305\/revisions"}],"predecessor-version":[{"id":15407,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/14305\/revisions\/15407"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=14305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=14305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=14305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}