5

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?

Trevor Reid
  • 3,310
  • 4
  • 27
  • 46
  • 2
    Please find the answer here https://stackoverflow.com/questions/52453260/powershell-ise-how-to-run-new-powershell-version – 2 B Apr 17 '19 at 16:31

5 Answers5

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!

cet51
  • 1,196
  • 2
  • 11
  • 29
  • Thanks @cet51 it is helpful. I will likely work with VSCode irl, which is familiar. However the [Microsoft lab that I'm working through](https://github.com/kromerm/adflab) 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. – Trevor Reid Apr 17 '19 at 18:08
  • 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. – Trevor Reid Apr 17 '19 at 18:20
  • 1
    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. – cet51 Apr 17 '19 at 18:25
  • 1
    Update: [PowerShell 7 was released this week](https://devblogs.microsoft.com/powershell/announcing-powershell-7-0/) – Magnetron Mar 06 '20 at 11:21
2

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

Jeremy F.
  • 1,778
  • 11
  • 51
  • 86
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/

js2010
  • 23,033
  • 6
  • 64
  • 66
2

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.

Trevor Reid
  • 3,310
  • 4
  • 27
  • 46
thatguyfig
  • 239
  • 1
  • 7
0

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.

Djongov
  • 195
  • 2
  • 13