Photo by Kelly on Pexels.com

Description

PowerShell is a powerful tool but sometimes certain features or functionalities may not be available in all versions of PowerShell.

To address this issue, PowerShell 7 introduced a lot of new features and enhancements compared to its predecessor PowerShell 5. However, PowerShell 5 is still widely used and CAN co-exists with PowerShell 7 in many environments. Here are a few approaches to handle the co-existence of PowerShell 7 and PowerShell 5.

  1. Dual Installation: Install both PowerShell 7 and PowerShell 5 on your system. This way, you can use PowerShell 7 for tasks that require the latest features and PowerShell 5 for compatibility with older scripts or modules.
  2. Module Versioning: When working with modules, you can specify the required version for compatibility. This way, you can ensure that the correct version of the module is loaded based on the PowerShell version being used.

Remember, it’s important to test and validate scripts and modules across different PowerShell versions to ensure compatibility and proper functionality. Co-existing PowerShell 7 and PowerShell 5 can provide a comprehensive solution to tackle the challenge of missing features or version-specific requirements.

To run PowerShell 7 and PowerShell 5 co-existently on a Windows Server 2016, you can follow these steps:

  • Check PowerShell Versions: First, verify the PowerShell version installed on your Windows Server 2016 by opening a PowerShell window and running the Get-Host command. Note the version number displayed.

  • Install PowerShell 7: Download and install PowerShell 7 from the official PowerShell GitHub repository.
  • Double click the exe and follow the on screen instructions. By default, PowerShell 7 will be installed side-by-side with the existing PowerShell version.
PS C:\WINDOWS\system32> GET-HOST
Name             : ConsoleHost
Version          : 5.1.22621.2506
InstanceId       : ca47a9b2-007a-4aa6-b2ea-0a5fb7da9b67
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-IN
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

  1. Set up Dual Installation: To set up a dual installation, you need to create a new shortcut for PowerShell 7.
  2. Right-click on an empty area of your desktop or file explorer
  3. Select “New,” and choose “Shortcut” from the menu. In the shortcut window, enter the following command:
    pwsh.exe -NoLogo

    Click “Next” and give a name to the shortcut, e.g., “PowerShell 7.”

  4. Use Powershell 7 shortcut to launch Powershell 7 and use the default powershell for Powershell 5.

ith these steps, you should now have PowerShell 7 and PowerShell 5 co-existing on your Windows Server 2016 machine. You can choose the appropriate version based on your requirements and leverage the specific features available in each version.

Thank you for reading !