Public Preview of PowerShell Support in Jupyter Notebooks

Avatar

Tyler

Public Preview of PowerShell Support in Jupyter Notebooks

Today, the .NET team shipped an exciting new preview of .NET Interactive. If you’re unfamiliar, .NET Interactive (within a Jupyter environment) provides the ability to write .NET Jupyter Notebooks which are a powerful tool that combines documentation and the ability to execute and see the output of code all in the same file.

It’s especially exciting to us because it includes a preview of PowerShell support!

NOTE: We want to be super clear. This is an early preview which has the main goal of getting early feedback from real usage so we can make informed decisions as we continue to develop. It’s not feature complete and we’ve enumerated some of the unfinished features at the bottom. Also, because this is a preview, we will continue to improve the experience which includes making breaking changes.

If you want to try it out right this second, you can play around with it using MyBinder which will provision a linux-based container for you with JupyterLab all ready to go:

Launch on MyBinder!

Otherwise, read on for context.

What are Jupyter Notebooks

The Jupyter Notebooks concept combines executable code and documentation into one interactive experience. The Notebooks experience has been popping up all over and is in products such as:

  • JupyterLab & Jupyter Notebook – web-based interactive development environment for Jupyter notebooks available in a hosted environment or a local download.
  • Azure Notebooks – A hosted Notebooks experience provided by Microsoft Azure.
  • Azure Data Studio – A rich text editor you can download with a native Notebooks experience (Supports PowerShell already using a different implementation!).
  • Many many more!

Although there are a bunch of offerings they all look similar to this:

A sample PowerShell Jupyter Notebook

Notice the mix of rich documentation (which is represented in markdown), code, and the output of said code.

What is .NET Interactive

.NET Interactive is a tool provided by the .NET team that allows you to create Jupyter Notebooks that use .NET languages.

With today’s announcement, .NET Interactive now supports:

  • C#
  • F#
  • PowerShell (new!)

Mixing languages

One area where .NET Interactive excels is the ability to mix languages in the same Notebook. Here’s an example of a C# Notebook that calls out to PowerShell:

Call out to pwsh

Using the “magic command” #!pwsh tells .NET Interactive to run that cell using PowerShell.

Why we think PowerShell is great for Notebooks

PowerShell is and has always been strong as an interactive experience. Write some code, run it, write more code, change some code, run it.

Jupyter Notebooks also focus heavily on this concept which makes Jupyter and PowerShell a perfect match.

The demand is there

We’ve seen a number of community efforts to add PowerShell support to Jupyter:

Live in production

As I mentioned above, Azure Data Studio already supports PowerShell in their Notebook experience using vors/jupyter-powershell mentioned above. DBAs, BI specialists, and other data heavy folks have been leveraging PowerShell within a Notebook experience already and it has seen fantastic growth.

As we continue to work on stabilizing the PowerShell support in .NET Interactive, we expect to see .NET Interactive support in Azure Data Studio in the future.

Troubleshooting guides in mind

It’s a common scenario. A team uses a OneNote, a bunch of markdown, or similar to keep all their troubleshooting guides in one place.

The downside there is that the code within that OneNote or markdown isn’t executable… and with OneNote, keeping things up to date can be hard without a source control system like git.

We believe that Notebooks would be a viable replacement and huge time saver for these folks.

Notebooks are easily shareable and can be put into a git repo or other source control system.

What’s supported in this Preview of PowerShell Support

If you’d like to see an example Notebook that I created using .NET Interactive while testing, check out this GitHub gist which has an overview of what’s supported.

Running code

This one might be obvious… but today, you can run PowerShell code inside of a Jupyter Notebook.

All the normal streams are supported and output looks exactly like it does in a normal PowerShell console.

All PowerShell streams are supported

Progress support

We have very basic support for ProgressRecords as made famous by the Write-Progress cmdlet.

progress support

Installing Modules

Installing modules via PowerShellGet is possible as PowerShellGet is bundled with .NET Interactive.

NOTE: There’s currently no ability to read from the host so if you want to install a module, you MUST use -Force. This limitation is actively being worked on but is not available at this time.

One of the big things we want to investigate is how we can make PowerShell Jupyter Notebooks incredibly easy to share. To do this, we may want to make Notebooks as isolated as possible meaning new modules installed will only be installed for the Notebooks environment and won’t mess up your existing installation of PowerShell.

Let us know if you have thoughts on how we can improve the “sharability” of a PowerShell Notebook.

What’s not supported yet

Reading from the Host

This feature is currently in development but is not in this release.

There’s currently no way to prompt the user in .NET Interactive. This means cmdlets like Read-Host and Get-Credential won’t work.

This also means that cmdlets that use ShouldProcess or modules like PowerShellGet that ask you to confirm installation will hang if you don’t use -Force.

We’re working on a way to support this but it’s still early days.

Richer formatting

We’d like feedback on what you expect here before we begin development.

Today, formatting looks exactly like it does in the console. This is good for an initial release but we want to leverage Jupyter’s ability to display rich HTML to bring formatting to a whole new level (think sortable headers, color coding, etc).

Plotting

We’d like feedback on what you expect here before we begin development.

In .NET Interactive’s C# and F# support, there’s an ability to plot data points on graphs and display them in the Notebook.

Today, PowerShell doesn’t have this capability but if there is enough ask, we can experiment with adding support for it.

Where to open issues/feature requests

You can open issues or feature requests in the .NET Interactive GitHub repo.

Have an idea for how you’re going to use Notebooks? Fill out this form and let us know so we can keep it in mind as we build out this experience.

We’re looking forward to hearing how you use this experience!

Tyler Leonhardt Software Engineer PowerShell Team Twitter | GitHub

3 comments

Comments are closed.