PowerShell 7.1 may not look like it has huge changes at first glance, but there is a lot more going on under the hood than one may expect. There are also a number of very useful features and tools that can enhance your scripting and help you develop even better scripts. PowerShell 7.1 was released on 11/11/2020 and is quickly becoming adopted by many in the IT community. This article goes into a number of improvements and enhancements but is by no means a comprehensive collection of all the improvements.
By the biggest improvement is that of PowerShell 7.1 being built on the just-released .NET 5. This is a major release that continues the unification journey that .NET has been on with traditional .NET and .NET Core. With .NET 5 the first steps into a unified core are realized. PowerShell 7.1 takes advantage of the many performance improvements and language improvements.
Updated Core Modules and Loading Improvements
PowerShell 7.1 includes several core module updates. Notably, PSReadLine 2.1.0 now includes predictive IntelliSense, which is a fish shell-like syntax prediction engine. Additionally, there have been many fixes to the vi-mode and the added ability to set the
MaximumHistoryCount from a user profile.
WinCompat module loading, PowerShell 7 modules are now treated with a higher priority. This prevents inadvertent overwriting of the core modules when using the
WinCompat mode to enable non-native PowerShell 7 modules to work within the updated PowerShell version.
New Engine Features
There are, of course, several new core features that are useful. The main three are:
- TLS 1.3 support
Null conditional operators were actually introduced back in PowerShell 7 but as an experimental feature. This feature has now been made mainstream and included by default in PowerShell 7.1. There are two new operators that are
# This typically replaces an if null statement and will run the output if the value is null. $Object ?? '$object contains a $null value' # When the value of the conditional is null then, assign that object to the value on the right of the conditional. $Object ??= 'This value is assigned on a $null $object'
Next, we have the
PSUnixStat option, this file states that it is now moved out of experimental but sometimes may still appear as experimental. This feature will only be available on Linux systems. You can find out its status and turn on the feature by doing the following.
# Make sure this feature is enabled, will need to restart the PowerShell session Get-ExperimentalFeature -Name 'PSUnixFileStat' | Enable-ExperimentalFeature
This feature will give you a new
UnixMode property that displays information from the Unix
stat command. This is very useful for those used to working with traditional Linux permissions.
Finally, TLS 1.3 support is now included in the various web cmdlets such as
Invoke-WebRequest. For those that want to utilize the performance and security enhancements that are included in this new TLS version and can interact with an endpoint capable of that, this will be a very useful addition. If the site supports TLS 1.3, the content will be returned and negotiated by the new protocol version.
Invoke-RestMethod -Uri '<https://mysite.com>' -SslProtocol Tls13
There are a handful of additional features and improvements that help to enhance your script abilities and structure.
- Within the Windows environment,
Start-Processwill now, by default, include all environment variables from the current session. Only when using the
UseNewEnvironmentparameter will an environment be created with new process variables.
ForEach-Object -Parallelcommand will now reuse runspaces. This will improve memory and performance usage. For those concerned that maximum runspace isolation is not being achieved, the parameter
UseNewRunspaceis now included to create a brand new runspace for each pipeline iteration.
Get-Randomcommand now includes the
Shuffleparameter. This will take a collection piped into
InputObjectand return the same collection but shuffled in order.
- Add the parameter
Get-Datecommand. This simplifies the traditional conversion utilities needed, such as with the
- Implement the
Stop-Computercmdlet for Linux and macOS systems. This relies on the binary
/sbin/shutdownbeing available. If the OS is Linux, the argument passed is
nowand if the OS is macOS then the argument passed is
- Similar to
Restart-Computeris now implemented for Linux and macOS systems. This uses the binary
/sbin/shutdownand passes the argument of
Finally, there is a handful of breaking changes. There are more listed, but these two may affect scripts more than others.
- The rename of
Get-Datecmdlet to allow Unix time input may impact scripts that use this feature and will need to be updated.
- Do not wrap return result to
PSObjectwhen converting ScriptBlock to delegate types. This is a edge case situation when casting a scriptblock and you want the return type to be the original object and not cast to a PSObject.
PowerShell 7.1 may not seem like it has introduced huge new features, but there are many incremental improvements and major backend engine enhancements. The PowerShell ecosystem and language continues to improve with every iteration and is quickly becoming a popular and staple language for system administrators everywhere.
This post was written by Adam Bertram and was first posted to www.cloudsavvyit.com
Do you find this article helpful? Your Friend might too. So, please Share it with them using the Share button above.
Will you like to get notified when I post new updates? Then Follow me on any of my social media handles: Google News, Telegram, WhatsApp, Twitter, Facebook, Pinterest.
You can also drop your email address below if you wish to be notified by mail.