Blog Post

PowerShell Notebooks are Available in Azure Data Studio

,

PowerShell Notebooks are now available in the November release of Azure Data Studio. Back in March I requested this feature be added to Azure Data Studio and it has become the most popular feature request for Notebooks. (Although, I’m sure it only became the most popular after they added copying from the results grid a few months ago )

In Azure Data Studio, open up a new Notebook and change the drop-down menu next to “Kernel:” and select PowerShell

At this point, if you haven’t tried out the Python kernel yet, you will be asked if you want to use an existing install of Python, or let Azure Data Studio install Python. I already have Python installed, so I will point it to that install.
If you have already used the Python 3 kernel, you can skip these next two screenshot and head straight down to installing the powershell_kernel.

(At this next point, if you’ve never installed or used any kernel besides the SQL kernel, you will see a lot of downloading & installing happening. This could take a little while.)

The Notebook dependencies may take a few minutes to install.

To get PowerShell Notebooks up & running you’ll need to install the powershell_kernel package. To do that, you’ll need to go through the following steps:

  1. Back inside that Notebook, click on the “Manage Packages” button (if the “Manage Packages” button isn’t being displayed, just choose the “Python 3” kernel or close the Notebook and re-open it)
  2. When the fly-out menu pops out from the right, click in “Add new
  3. In the search box type in powershell_kernel
  4. Click “Search
  5. Once the powershell_kernel is found, click “Install

After all that, the powershell_kernel should finish installing rather quickly.

Once the install completes, go back to your Notebook and switch the Kernel dropdown to PowerShell if it isn’t already.  Next, a new Code cell and start adding your PowerShell code to your Notebook.

Note: Sometimes the dropdown gets stuck on Changing Kernel, if this happens to you, the easiest thing may be to close out of that Notebook and start a new one.

Make sure to install the PowerShell extension

In order to get all the nice intellisense and tab completion features of the PowerShell language inside your PowerShell Notebooks, be sure to install the PowerShell extension from the Azure Data Studio marketplace.

Once you have your command ready to go, just hit the “Run cell” button and you’ll see your results returned in that same cell. When you save your Notebook file, you can choose to clear out these results or leave them in there, so the next person knows what the results are supposed to look like. Or, you just know that yes your code did work the last time you ran it

Now before you get rocking & rolling with PowerShell Notebooks there are a few things you should know.

  1. PowerShell Notebooks run Windows PowerShell on Windows, and PowerShell Core on macOS & Linux (this was just the easiest / fastest kernel to get working)
  2. [For now] when you run a code cell in a PowerShell Notebook it runs the code by passing whatever code you gave it to PowerShell.exe as a scriptblock and also passes the -NoProfile switch. This makes sense to do as a default, but I suspect some customers will want an option to turn off -NoProfile for some of their PowerShell Notebooks
  3. You can set a variable in one cell, and pull the values out of it in a different cell. Until you close your Notebook or Azure Data Studio, you can reuse variables from one code cell to another. Each code cell is participating in the same common execution of PowerShell

So that’s all well and good. But if you’ve read many of my blogs or articles over the years, you know I still have one burning question: Will PowerShell Notebooks work with Out-GridView?

I am happy to tell you that, if you’re on Windows, yes, PowerShell Notebooks does work with Out-GridView!

That’s pretty much everything I have to show you about PowerShell Notebooks for today. There are a few other features I will call out in a future post or two, but this should be enough to get you started with PowerShell Notebooks.

I do have a few open enhancement requests in the Azure Data Studio repo with ideas of how to make PowerShell Notebooks even better. Please have a look comment with what you plan to do with PowerShell Notebooks you build?

The post PowerShell Notebooks are Available in Azure Data Studio first appeared on SQLvariations: SQL Server, a little PowerShell, maybe some Power BI.

Original post (opens in new tab)
View comments in original post (opens in new tab)

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating