December 15th, 2020

PowerShell 7.2 Preview 2 release

Steve Lee
Principal Software Engineer Manager

PowerShell 7.2 Preview 2

Today we are proud to announce the second preview release of PowerShell 7.2. This preview is still based on .NET 5 as we wait for the first preview of .NET 6 which we expect PowerShell 7.2 to be based upon.

This preview includes many changes including code cleanup, bug fixes, and a few new features.

Code cleanup

The community has made significant contributions to code cleanup which is a focus early in a new release. Approximately two thirds of the 120 pull requets were for code cleanup!

Thanks to all the community members involved in submitting pull requests and reviewing them!

Notable bug fixes

Although we appreciate all bug fixes from the community, there are a few I believe have a broader impact and worth mentioning.

Correct handling of Windows invalid reparse points

On Windows, reparse points are a collection of user-defined data that define specific filesystem behaviors. For example, symbolic links, OneDrive files, and Microsoft installed applications use reparse points. Due to a bug introduced in PowerShell 7.1, if you try to use an executable on a drive that isn’t NTFS, you’ll get an Incorrect Function error. This can be a local USB drive or a network share, for example.

Thanks to our community maintainer Ilya Sazonov for the fix.

We expect to backport this fix to PowerShell 7.1 for the next servicing release.

Breaking changes

-PipelineVariable common parameter

The -PipelineVariable common parameter now correctly contains all the objects passed in from the pipeline making script cmdlets work the same as C# cmdlets instead of just the first input object.

You can see an example of the change in behavior in the original issue.

Thanks to Joel Sallow for the fix.

New features

$PSStyle automatic variable for ANSI rendering

When working in the console with a modern terminal, color and text effects can help make text information more interesting and useful.

This experimental feature called PSAnsiRendering exposes a new $PSStyle automatic variable that can be used for two different purposes.

The first is to make it easier to author text content that contains ANSI escape codes which control text decorations like color, bold, italics, etc…

This example simply dumps the contents of $PSStyle and shows you the members you can use and their effect on text as well as the actual ANSI escape sequence. Note that the custom formatting for this variable includes nested types like Formatting, Foreground, and Background.

$PSStyle variable

You can use multiple ANSI escape sequences together. In this example, I’ve set warning messages to have bold and italicized yellow text on a magenta background:

Warning message style customization

There are also FromRgb() methods available to make use of full 24-bit color if your terminal supports it:

24-bit color text

C# module authors can also leverage $PSStyle by using the PSStyle singleton class in the System.Management.Automation namespace:

string text = $"{PSStyle.Instance.Reverse}{PSStyle.Instance.Foreground.Green}PowerShell{PSStyle.Instance.Foreground.Yellow} Rocks!{PSStyle.Instance.Reset}";

You can control how PowerShell outputs strings that contain ANSI escape sequences by setting $PSStyle.OutputRendering:

  • Automatic This is the default and currently will output the text as-is whether it is to the host or through the pipeline if the terminal supports ANSI escape sequences (otherwise the output will be plaintext). This is similar behavior to what you would get on Linux.
  • Ansi This value will output the text as-is whether it is to the host or through the pipeline.
  • PlainText This value will remove ANSI escape sequences from any text output whether it is to the host or through the pipeline.
  • Host This value will output the text as-is if sent to the host if ANSI escape sequences are supported, but will output plaintext if the output is sent through the pipeline or redirected. This is similar behavior to what you would get on macOS.

As this is an experimental feature, we encourage feedback on this before we make a decision to take it out of experimental. See the original issue for additional details, but open new issues if you have any problems or suggestions on how to improve this feature.

We very much appreciate on going feedback on our preview releases so we can make adjustments before the release is finalized. Please participate in on going discussions or create new issues in our repo.

Thanks again to the PowerShell community and all the amazing contributors!

Category
PowerShell

Author

Steve Lee
Principal Software Engineer Manager

Principal Software Engineer Manager PowerShell 7, PowerShellGet, PSScriptAnalyzer, VSCode-PowerShell extension, PowerShellEditorServices, etc...

8 comments

Discussion is closed. Login to edit/delete existing comments.

  • Michael Mientus

    Is there any update on the MSIX packages? I found it useful to have them in GitHub releases.

    • Steve LeeMicrosoft employee Author

      We currently only publish MSIX to the Microsoft Store

  • Felix Rabinovich

    OMG – Microsoft site (even if blog site) is flooded by spam!

    • Steve LeeMicrosoft employee Author

      Unfortunately, it’s manual to mark them. I’ve marked all current comments that have a link to something unrelated as spam.

  • Mystery Man

    Hello, Steve.

    You wrote: “C# module authors can also leverage $PSStyle by using the PSStyle singleton class in the System.Management.Automation namespace”

    They probably won’t, even if your example doesn’t scare them outright. They already have access to the much better Spectre.Console package on NuGet. This package uses a markup syntax.

    • Steve LeeMicrosoft employee Author

      Developers can always choose whatever library they want to use for generating ANSI escape sequences. The point about using PSStyle from C# is things like reading user configuration for `FormatAccent`, for example.

      • Mystery Man

        Now, that’s actually a good point. 👍 Maybe you should start with that next time.

      • Samuel · Edited

        Yup the same I was thinking to do, cuz c# is quitely good 🙂