What Powershell version will run after installing 7 - powershell

I have a server that executes many PowerShell scripts.
PowerShell 5.1 is installed.
PowerShell 7 is not installed.
If I install PowerShell 7, what PS version will the existing scripts "run on"? 5.1 or 7?
If existing scripts will default to use 7, how can I force existing scripts to use 5.1?

Related

PowerShell ISE: how to run new PowerShell version

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...

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.

How do I run PowerShell 4.0 after upgrading from PowerShell 2.0?

I have installed DotNet 4.5.2 and PowerShell 4 on my Windows 7 SP 1 workstation using chocolatey:
choco install dotnet4.5.2 -y
choco install powershell -y
They installed without errors and appear in the choco list:
choco list --local-only
DotNet4.5.2 4.5.2.20140902
PowerShell 4.0.20141001
I previously had PowerShell 2.0 installed, and when restarting PowerShell, the $host.version still shows Major: 2. In addition, it appears that PowerShell 4.0 only exists in the \Program Files (x86) not in \Windows, and when I list the contents of the 3.0 directory, only assemblies (no executables) are listed.
> dir 'C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell'
3.0
v1.0
> dir 'C:\Windows\System32\WindowsPowerShell'
v1.0
> dir 'C:\Windows\SysWOW64\WindowsPowerShell'
v1.0
Where does the PowerShell 4.0 executable live? How can I run PowerShell 4.0 instead of 2.0?
I needed to restart my computer for windows update to install Microsoft Windows Management Framework 4.0

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.