7

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?

1

5 Answers 5

8

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!

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks @cet51 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.
To answer my own comment @cet51 If I understand correctly upgrading to PS 5.1 was not noticed by the console. I updated the question.
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.
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/

Comments

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.

2 Comments

How can I make the change permanent?
The line Host.PushRunspace($Runspace) caused an error. I removed it.
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

1 Comment

your link is dead. please do not just link but include solution code here.
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.

1 Comment

the link is dead

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.