All Projects → dataplat → ADSNotebook

dataplat / ADSNotebook

Licence: GPL-3.0 license
PowerShell Module for interacting with Azure Data Studio Notebooks

Programming Languages

powershell
5483 projects

ADSNotebook

A module for creating Azure Data Studio Notebooks with PowerShell

Build Status

Functions

This module contains only 3 commands at present

Convert-ADSPowerShellForMarkdown

This will create the markdown link for embedding PowerShell code in a Text Cell for a SQL Notebook as described in Rob's blog post here

https://sqldbawithabeard.com/2019/07/17/powershell-in-sql-notebooks-in-azure-data-studio/

New-ADSWorkBookCell

This command will create a workbook text cell or a code cell for adding to the New-ADSWorkBook command

New-ADSWorkBook

This will create a new SQL Notebook using the cell objects created by New-ADSWorkBookCell. You can create a PowerShell or SQL Notebook. There are a couple of blog posts to read here

https://sqldbawithabeard.com/2019/11/07/create-azure-data-studio-sql-notebooks-with-powershell/

https://sqldbawithabeard.com/2019/11/14/create-a-powershell-notebook-for-azure-data-studio-with-powershell/

Usage

Convert-ADSPowerShellForMarkdown

Convert-ADSPowerShellForMarkdown -InputText "Get-ChildItem" -LinkText 'This will list the files' -ToClipBoard

Converts the PowerShell so that it works with MarkDown and sets it to the clipboard for pasting into a workbook cell

New-ADSWorkBookCell

$introCelltext = "# Welcome to my Auto Generated Notebook

## Automation
Using this we can automate the creation of notebooks for our use
"
$Intro = New-ADSWorkBookCell -Type Text -Text $introCelltext
Creates an Azure Data Studio Text cell and sets it to a variable for passing to  New-AdsWorkBook
$thirdcelltext = "SELECT Name
FROM sys.server_principals
WHERE is_disabled = 0"
$Third = New-ADSWorkBookCell -Type Code -Text $thirdcelltext

Creates an Azure Data Studio Code cell which will be collapsed and sets it to a variable for passing to New-AdsWorkBook

New-ADSWorkBook - SQL

$introCelltext = "# Welcome to my Auto Generated Notebook

## Automation
Using this we can automate the creation of notebooks for our use"
$SecondCelltext = "## Running code
The next cell will have some code in it for running

## Server Principals
Below is the code to run against your instance to find the server principals that are enabled"
    
$thirdcelltext = "SELECT Name
FROM sys.server_principals
WHERE is_disabled = 0"
$Intro = New-ADSWorkBookCell -Type Text -Text $introCelltext
$second = New-ADSWorkBookCell -Type Text  -Text $SecondCelltext
$third = New-ADSWorkBookCell -Type Code -Text $thirdcelltext
    
$path = 'C:\temp\AutoGenerated.ipynb'
New-ADSWorkBook -Path $path -cells $Intro,$second,$third -Type SQL

Creates 3 cells with New-AdsWorkBookCells to add to the workbook, two text ones and a code one, then creates a SQL Notebook with those cells and saves it as C:\temp\AutoGenerated.ipynb

New-ADSWorkBook - PowerShell

$introCelltext = "# Welcome to my Auto Generated PowerShell Notebook

## dbatools
![image](https://user-images.githubusercontent.com/6729780/68845538-7afcd200-06c3-11ea-952e-e4fe72a68fc8.png)  

dbatools is an open-source PowerShell Module for administering SQL Servers.
You can read more about dbatools and find the documentation at [dbatools.io](dbatools.io)
"
$SecondCelltext = "### Installation
You can install dbatools from the PowerShell Gallery using `Install-Module dbatools`
"

$thirdcelltext = "Install-Module dbatools"

$fourthCelltext = "### Getting Help
You should always use `Get-Help` to fins out how to use dbatools (and any PowerShell) commands"

$fifthcelltext = "Get-Help Get-DbaDatabase"
$sixthCelltext = "Try a command now. get the name, owner and collation of the user databases on the local instance"
$seventhCellText = "Get-DbaDatabase -SqlInstance localhost -ExcludeSystem | Select Name, Owner, Collation"

$Intro = New-ADSWorkBookCell -Type Text -Text $introCelltext
$second = New-ADSWorkBookCell -Type Text -Text $SecondCelltext
$third = New-ADSWorkBookCell -Type Code -Text $thirdcelltext
$fourth = New-ADSWorkBookCell -Type Text -Text $fourthCelltext
$fifth = New-ADSWorkBookCell -Type Code -Text $fifthcelltext
$sixth = New-ADSWorkBookCell -Type Text -Text $sixthCelltext
$seventh = New-ADSWorkBookCell -Type Code -Text $seventhCellText

$path = 'C:\temp\dbatools.ipynb'
New-ADSWorkBook -Path $path -cells $Intro,$second,$third,$fourth,$fifth,$sixth,$Seventh -Type PowerShell

Installation

You can install this Module from the PowerShell Gallery using

Install-Module ADSNotebook

Compatability

This module has been tested on Windows PowerShell 5.1, PowerShell Core 6 and PowerShell 7 on Windows 10 and Ubuntu

Demo

https://sqldbawithabeard.com/wp-content/uploads/2019/11/New-ADSNoteBook.mp4

Silly video of Notebook inception! Creating a PowerShell Notebook that creates a PowerShell Notebook with PowerShell https://sqldbawithabeard.com/wp-content/uploads/2019/11/2019-11-14_12-22-40.mp4

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].