PowerShell ISE: how to run new PowerShell version - powershell

How can I get PowerShell ISE to work with PowerShell 6.0. Currently, it has 4.0.
This server has PowerShell 4.0 installed and I installed PowerShell 6.0 with PowerShell-6.1.0-win-x64.msi from this link: https://github.com/PowerShell/PowerShell/releases
The files now exist in C:\Program Files\PowerShell\6.
However, ISE still shows 4.0, but I need it to run 6.0
$PSVersionTable.psversion
Major Minor Build Revision
4 0 -1 -1

PowerShell has 3 executables...
Windows only...
PowerShell_ISE.exe = ISE v2 - v5.1
powershell.exe = consolehost v1 - 5.1
Note: (there are no new versions coming, but this will be supported going forward as it is today, as per Microsoft announcements, just nothing new coming to it. Just bug /security fixes.)
Cross-platform
pwsh.exe = PowerShell Core/v6
The editor to use if you are using v6 is Visual Studio Code, which is also cross-platform, unlike the ISE.
https://code.visualstudio.com/Download
The are no plans to make the ISE leverage pwsh.exe/PSCore.
However, you can continue to use the ISE, and if you need something specifically to leverage PSCore, you have to shell out to it just as you would to cmd.exe. Your code will run the pwsh.exe console, and return you back to the ISE, depending on how you shell out to it.

What you are using is Windows PowerShell ISE which is always has Windows PowerShell as the integrated shell, you need VSCode here, where you can select which version of PowerShell to use ...
Just need to change below item in File -> Preferences -> Settings.
"terminal.integrated.shell.windows": "C:\\Program Files\\PowerShell\\pwsh.exe"
Same can be done via UI in few clicks as well...

Related

Is it possible to use Powershell 7 as the debug console version in Visual Studio Code? [duplicate]

What is the difference between [pwsh] and [Powershell Integreted Console] on VS Code?
I usualy use pwsh.
Today, when I installed the powershell extension and then tried to update the powershell, the Powershell Integreted Console started up and found out. What is this?  
pwsh[.exe] is the executable file name of PowerShell [Core] (v6+), the cross-platform edition of PowerShell built on .NET Core / .NET 5+; by contrast, powershell.exe is the executable name of the legacy Windows PowerShell edition (v5.1-), built on the Windows-only .NET Framework (v4.8-)
Windows PowerShell comes with Windows itself, whereas PowerShell [Core] must be installed on demand (on all supported platforms).[+]
VSCode (Visual Studio Code) has an integrated terminal (console) that can run any shell, such as cmd.exe, bash, or pwsh or powershell.
Shells that run in the integrated terminal by default have no special integration with the files being edited. They show by their executable file name in the dropdown list in the integrated terminal's toolbar; e.g.:
By contrast, the PowerShell Integrated Console is a special shell that comes with the PowerShell extension and offers integration with PowerShell code being edited, notably to provide linting and debugging support, among other features.
The PowerShell Integrated Console starts on demand when you first open/activate an editor with PowerShell code in a session, and it shows as follows in the integrated terminal's toolbar:
You can use the PowerShell extension's configuration to choose the specific PowerShell executable to use, which on Windows allows you to choose between running PowerShell [Core] (pwsh.exe) and Windows PowerShell (powershell.exe) in the PowerShell Integrated Console.
If a PowerShell [Core] version is installed and it is installed in a well-known location[*], it will be used by default; the fallback on
Windows is Windows PowerShell. Since PowerShell [Core] versions can be installed side by side, you can switch between different versions, if installed.
If a PowerShell [Core] version in installed in a nonstandard location and is therefore not discovered automatically, you can tell the PowerShell extension where to find it, either via the Settings GUI or via settings.json, as shown in the linked topic and the bottom section of this answer.
Whenever the active tab is a PowerShell source-code file, the status bar in the bottom-right corner shows the PowerShell version that is being used if you however over or click on the {} icon; versions >= 6 imply PowerShell [Core].
If configured, there's a separate icon that directly invokes the PowerShell session menu when clicked and which reflects the active version number - again, see the bottom section of this answer; e.g.:
[+] as of v7.0; time will tell if PowerShell [Core] will ship with future versions of Windows, and perhaps even other platforms.
[*] From the linked docs: "This feature looks at a few well-known paths on different operating systems to discover install locations of PowerShell. If you installed PowerShell to a non-typical location, it might not show up initially in the Session Menu. You can extend the session menu by adding your own custom paths." If you use one of the official installers, the PowerShell extension should find your installation.

How to point to Powershell version 3 from Powershell 4?

I am using Powershell v4.
By typing the following command i am able to switch to PowershellV2.
Powershell -Version 2
But the below is not working. It stays in Powershell v4.
Powershell -Version 3
how to switch to Powershell v3 from v4? The reason behind is given below.
In our customer environment Powershell v3 will be there and they are not going to migrate to .Net 4.5.2 for this release (it means they can't go to Powershell v4). but in our environment we have upgraded. Now we would like to test our scripts in v3 environment.
I guess this is by design.
https://technet.microsoft.com/en-us/library/hh847736.aspx
Applies To: Windows PowerShell 2.0, Windows PowerShell 3.0, Windows PowerShell 5.0
-Version <Windows PowerShell Version>
Starts the specified version of Windows PowerShell. The version that you specify must be installed on the system. If Windows PowerShell 3.0 is installed on the computer, valid values are "2.0" and "3.0". The default value is "3.0".
If Windows PowerShell 3.0 is not installed, the only valid value is "2.0". Other values are ignored.

PowerShell IntelliSense targeting older versions of PowerShell

Newer versions of the PowerShell ISE (and third-party PowerShell scripting environments like PowerGUI) offer pretty good IntelliSense support.
However, I often write scripts that I want to run on servers which only have older versions of PowerShell installed (in particular, PowerShell 2.0 on Windows Server 2008 R2). I can't upgrade the PowerShell installation on the server and the PowerShell 2.0 ISE doesn't have IntelliSense.
Is there any way to configure the PowerShell 3.0 or 4.0 ISE, or PowerGUI (or any other free PowerShell script editor!) to provide IntelliSense which is restricted to PowerShell 2.0 compatible code only?
I have confirmed Jason's theory that Intellisense does work in PSRemoting against the installed version of Powershell, but it looks a bit different. I tested using Powershell preview build 5.0.10018.0 remoting to Server 2008R2 with PS v2.0. I ran:
$Procs = Get-Process
$Procs <Ctrl + Space>
This resulted in an Intellisense tooltip with options like:
$Procs.count
$Procs.Clear(
Where v3.0 and up would only include the property or method names, not the variable itself.
I also tested for the .Where() and .Foreach() magic methods which did not show up in Intellisense. This seems to confirm that it's working against the installed version.

Can I install Powershell 4 side by side with Powershell 3?

I have Powershell 3 installed on my box.
I need to test some scripts with Powershell 4 but I want to continue to run some of my scripts that are tested under Powershell 3 and I do not want to break something by installing Powershell 4.
QUESTION:Is it possible to open a Powershell sessions under Powershell version 3 (or even 2 if needed) despite I have installed Powershell 4?
When you have the Windows Management Framework Core 4.0 package installed, you can run PowerShell version 2.0, but not 3.0. Use the -version 2.0 parameter to launch PowerShell v2.
See this TechNet article: http://technet.microsoft.com/en-us/library/hh847899.aspx
Also see the help about_powershell.exe help documentation: http://technet.microsoft.com/en-us/library/jj553275.aspx
Yes. Starting with V3, you could open a powershell session for a downlevel version using the -Version parameter.
-Version
Starts the specified version of Windows PowerShell.
Enter a version number with the parameter, such as "-version 2.0".
So running
Powershell.exe -Version 2
will start a session that can be used to run/test a V2 script.

TFS Powershell cmdlet not working in ISE

I am unable to run the following command in Powershell ISE but these exact same command works just fine in a regular Powershell console.
Get-TfsServer -name http://mytfsserver:8080
I tried adding the Snap-in from the ISE console but it did not help. I even added it to the Script Pane in ISE but it did not help.
I am on Win8 & TFS Power Tools 2012.
Any ideas?
It could be bitness issue. IIRC the TFPT PowerShell module is x86 only. It could be that it is working in an x86 PowerShell console but failing in a 64-bit ISE.
i hope you added pssnapin microsoft.teamfoundation.powershell in to the powershell ISE..
The ISE should be x64 bit. Since this snapin works in x64 bit only.
we dont have any command to check the bitness. but while opening the ISE itself it will show the bitness (if it is x86.)
x64 bit ISE will not show the bitness version.
kudos