This module includes the function Invoke-PowerShellNotebook
which enables you to run the cells inside the PowerShell notebook.
Convert-MarkdownToNoteBook
converts your markdown, recognizes fenced code blocks
and converts it, and "runs" the PowerShell, including that snippets results in an executable document, a PowerShell notebook.
- Share it with colleagues to better illustrate concepts
- Develop workflows other can use, for diagnostics, testing, and more
Convert-MarkdownToNoteBook .\multiplePSLines.md
Check out the Video Here
In a nutshell.
- Author your markdown with
Chapter Start and End
, then use fence blocks ``` to indic - In Azure Data Studio PowerShell console, run
Convert-MarkdownToNoteBook .\demo.md -watch
- When you save the file,
Convert-MarkdownToNoteBook
detects and auto converts it to aPowerShell Notebook
- When you save the file,
- The converted Interactive PowerShell Notebook. Note:
Convert-MarkdownToNoteBook
also runs the code from the markdown file and includes the results.
Sometimes you don't the results to be included in the converted PowerShell Notebook.
You can suppress evaluating the PowerShell code being run and the results being included by have the following comment as the first line in the fence block.
# Exclude Results
```ps
# Exclude Results
1+1
```
This will include the 1+1
in the interactive notebook, but will not evaluate the PowerShell statement and include it.
Below is a PowerShell Notebook with three cells, each containing a PowerShell "script".
Notice the second cell has the results of running get-process | select company, name, handles -first 10
Invoke-PowerShellNotebook
sports an AsExcel
switch. This lets you execute each cell in the PowerShell notebook and the function exports the results to a separate sheet in an Excel file.
You need to have the PowerShell ImportExcel
module installed. The module is on the PowerShell Gallery, use Install-Module ImportExcel
to install it on you machine.
You can also create PowerShell Notebooks outside if Azure Data Studio with this module. Here is an example.
It creates two code blocks and a markdown block, and saves it to a file C:\Temp\test.ipnyb
.
New-PSNotebook -NoteBookName c:\temp\test.ipynb {
Add-NotebookCode '$a=8'
Add-NotebookCode '$a+12'
Add-NotebookCode '$a+3'
Add-NotebookMarkdown @'
## Math
- show addition
- show other
'@
}
You can open c:\temp\test.ipynb
in Azure Data Studio and click Run Cells
If you've used start-demo.ps1
to setup PowerShell demos, this function will convert that format into a PowerShell Notebook.
ConvertTo-PowerShellNoteBook .\demo.txt .\demo.ipynb
Converts this to a PowerShell Notebook.
# Get first 10 process
ps | select -first 10
# Get first 10 services
gsv | select -first 10
# Create a function
function SayHello($p) {"Hello $p"}
# Use the function
SayHello World