Why doesn't Console in PowerShell ISE use the latest installed version of PowerShell?
Asked Answered
T

5

6

I have recently installed PowerShell 6.2.

If I start a PowerShell 6 (x64) command prompt and run $PSVersionTable.PSVersion this is the result

Major  Minor  Patch  PreReleaseLabel BuildLabel
-----  -----  -----  --------------- ----------
6      2      0

From the same prompt I run the ISE using powershell_ise.exe and the PowerShell ISE starts. However, in the console within ISE if I run $PSVersionTable.PSVersion it reports this:

Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      -1     -1  

Is there a setting to control where ISE looks for PowerShell? Or is there any way to ensure it is using the latest version installed?


UPDATE: As part of installing PowerShell Core (i.e. ver 6.2) I had to install Windows Management Framework 5.1. My understanding from this doc is that this should have upgraded the ISE console's version of PowerShell to 5.1 as well. I am still seeing ver 4.0 as noted above. What am I missing?

Toratorah answered 17/4, 2019 at 16:21 Comment(1)
Please find the answer here #52453760Character
S
7

The latest version of PowerShell is 5.1, this is the most recent version that you can use in ISE as well.

PowerShell 6 is also known as PowerShell Core, which is not supported in ISE. You can download a tool called Visual Studio Code that can be used with PowerShell 6 (Core).

Bonus: Interestingly enough, there was actually an article I read recently about a PowerShell 7 that Microsoft is currently working on which looks pretty interesting. See here as well for PowerShell 7.

Update: Thanks @Magnetron for updating in the comments. PowerShell 7 officially released this week.

Hope this helps!

Stockish answered 17/4, 2019 at 16:47 Comment(4)
Thanks @Stockish it is helpful. I will likely work with VSCode irl, which is familiar. However the Microsoft lab that I'm working through uses ISE. If I were to install 5.1 would the console use that automatically—for intro learning I find it's often helpful not to diverge from the script if it can be helped.Toratorah
To answer my own comment @Stockish If I understand correctly upgrading to PS 5.1 was not noticed by the console. I updated the question.Toratorah
That's definitely peculiar. When you upgrade the Windows Management Framework it also upgrades Windows Powershell, I had thought it upgraded the ISE version as well.Stockish
Update: PowerShell 7 was released this weekOrdovician
T
2

There's also a new feature in VSCode that emulates the ISE: https://devblogs.microsoft.com/powershell/visual-studio-code-for-powershell-7/

How to use ISE mode in VScode: https://www.thomasmaurer.ch/2020/03/how-to-use-powershell-ise-mode-in-visual-studio-code/

Tensiometer answered 6/3, 2020 at 13:45 Comment(0)
M
2

For those who wants a shorter version of enabling this.

Run this while in ISE (taken from the link from the other answers)

$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Clear()
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Switch to PowerShell 7", { 
        function New-OutOfProcRunspace {
            param($ProcessId)

            $ci = New-Object -TypeName System.Management.Automation.Runspaces.NamedPipeConnectionInfo -ArgumentList @($ProcessId)
            $tt = [System.Management.Automation.Runspaces.TypeTable]::LoadDefaultTypeFiles()

            $Runspace = [System.Management.Automation.Runspaces.RunspaceFactory]::CreateRunspace($ci, $Host, $tt)

            $Runspace.Open()
            $Runspace
        }

        $PowerShell = Start-Process PWSH -ArgumentList @("-NoExit") -PassThru -WindowStyle Hidden
        $Runspace = New-OutOfProcRunspace -ProcessId $PowerShell.Id
        $Host.PushRunspace($Runspace)
}, "ALT+F5") | Out-Null

$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Switch to Windows PowerShell", { 
    $Host.PopRunspace()

    $Child = Get-CimInstance -ClassName win32_process | where {$_.ParentProcessId -eq $Pid}
    $Child | ForEach-Object { Stop-Process -Id $_.ProcessId }

}, "ALT+F6") | Out-Null

Then re-launch your ISE and go to Add-ons button next to File, Edit, View ant etc. There should be a Switch to Powershell 7 option now.

That's it! 1 min job.

Mickens answered 4/3, 2021 at 9:48 Comment(2)
How can I make the change permanent?Schoolroom
The line Host.PushRunspace($Runspace) caused an error. I removed it.Schoolroom
M
1

I used the following link to add an add-on to Powershell ISE that will allow you to switch between Powershell 5 and 6. (See 'PowerShell ISE Add-On Command’) However, when you close out of Powershell ISE and open a new session you have to run the script again otherwise the option 'Add-ons' will not be there. I'm guessing the same process could be used when Powershell 7 is released.

Using PowerShell Core 6 and 7 in the Windows PowerShell ISE

Maunder answered 28/1, 2020 at 17:35 Comment(1)
your link is dead. please do not just link but include solution code here.Schoolroom
S
1

I would take a read of this guide - https://ironmansoftware.com/using-powershell-core-6-and-7-in-the-windows-powershell-ise/

It allows the ISE process to switch the backend PowerShell to be version 7. It even includes creation of a menu item and shortcut to swap the backend version. This is very handy and I have been using it with ISE for some time.

Severe answered 8/9, 2020 at 8:23 Comment(1)
the link is deadSchoolroom

© 2022 - 2024 — McMap. All rights reserved.