Why move to PowerShell 7 from Windows PowerShell?
The next major release of this venerable automation tool features performance improvements and a bevy of new features that could sway many administrators to switch.
PowerShell's evolution has taken it from a Windows-only tool to a cross-platform, open source project that runs on Mac and Linux systems with the release of PowerShell Core. Next on tap, Microsoft is unifying PowerShell Core and Windows PowerShell with the long-term supported release called PowerShell 7, due out sometime in February. What are advantages and disadvantages of adopting the next generation of PowerShell in your environment?
New features spring from .NET Core
Nearly rebuilt from the ground up, PowerShell Core is a departure from Windows PowerShell. There are many new features, architectures and improvements that push the language forward even further.
Open source PowerShell runs on a foundation of .NET Core 2.x in PowerShell 6.x and .NET Core 3.1 in PowerShell 7. The .NET Core framework is also cross-platform, which enables PowerShell Core to run on most operating systems. The shift to the .NET Core framework brings several important changes, including:
- increases in execution speed;
- Window Desktop Application support using Windows Presentation Foundation and Windows Forms;
- TLS 1.3 support and other cryptographic enhancements; and
- API improvements.
PowerShell Core delivers performance improvements
As noted in the .NET Core changes, execution speed has been much improved. With each new release of PowerShell Core, there are further improvements to how core language features and built-in cmdlets alike work.
With a simple Group-Object test, you can see how much quicker each successive release of PowerShell Core has become. With a nearly 73% speed improvement from Windows PowerShell 5.1 to PowerShell Core 6.1, running complex code in gets easier and completes faster.
Similar to the Group-Object test, you can see Sort-Object testing results in nearly a doubling of execution speed between Windows PowerShell 5.1 and PowerShell Core 6.1. With sorting so often used in many applications, using PowerShell Core in your daily workload means that you will be able to get that much more done in far less time.
Gaps in cmdlet compatibility addressed
The PowerShell team began shipping the Windows Compatibility Pack for .NET Core starting in PowerShell Core 6.1. With this added functionality, the biggest reason for holding back from greater adoption of PowerShell Core is no longer valid. The ability to run many cmdlets that previously were only available to Windows PowerShell means that most scripts and functions can now run seamlessly in either environment.
PowerShell 7 will further cinch the gap by incorporating the functionality of the current Windows Compatibility Module directly into the core engine.
New features arrive in PowerShell 7
There are almost too many new features to list in PowerShell 7, but some of the highlights include:
- SSH-based PowerShell remoting;
- an & at the end of pipeline automatically creates a PowerShell job in the background;
- many improvements to web cmdlets such as link header pagination, SSLProtocol support, multipart support and new authentication methods;
- PowerShell Core can use paths more than 260 characters long;
- markdown cmdlets;
- experimental feature flags;
- SecureString support for non-Windows systems; and
- many quality-of-life improvements to existing cmdlets with new features and fixes.
Side-by-side installation reduces risk
A great feature of PowerShell Core, and one that makes adopting the new shell that much easier, is the ability to install the application side-by-side with the current built-in Windows PowerShell. Installing PowerShell Core will not remove Windows PowerShell from your system.
Instead of invoking PowerShell using the powershell.exe command, you use pwsh.exe instead -- or just pwsh in Linux. In this way, you can test your scripts and functions incrementally before moving everything over en masse.
This feature allows quicker updating to new versions rather than waiting for a Windows update. By decoupling from the Windows release cycle or patch updates, PowerShell Core can now be regularly released and updated easily.
Disadvantages of PowerShell Core
One of the biggest drawbacks to PowerShell Core is losing the ability to run all cmdlets that worked in Windows PowerShell. There is still some functionality that can't be fully replicated by PowerShell Core, but the number of cmdlets that are unable to run is rapidly shrinking with each release. This may delay some organizations move to PowerShell Core, but in the end, there won't be a compelling reason to stay on Windows PowerShell with the increasing cmdlet support coming to PowerShell 7 and beyond.
Getting started with the future of PowerShell
PowerShell Core is released for a wide variety of platforms, Linux and Windows alike. Windows offers MSI packages that are easily installable, while Linux packages are available for a variety of different package platforms and repositories.
Simply starting the shell using pwsh will let you run PowerShell Core without disrupting your current environment. Even better is the ability to install a preview version of the next iteration of PowerShell and run pwsh-preview to test it out before it becomes generally available.