/
07 - Using PowerShell to Create a Notebook.ps1
60 lines (43 loc) · 1.83 KB
/
07 - Using PowerShell to Create a Notebook.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Install the module from the gallery
Install-Module ADSNotebook
# Look at the commands and the help
Get-Command -Module ADSNotebook
Get-Help Convert-ADSPowerShellForMarkdown -Detailed
Get-Help New-ADSWorkBook -Detailed
Get-Help New-ADSWorkBookCell -Detailed
#Create a Notebook
#cells
$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"
$fourthcelltext = "## SA renamed?
You should check if the sa account is in that list"
$fifthCellText = "We should try another Code cell"
$sixthcelltext = "## Are these sysadmin role members correct?
You should check the accounts in this list"
$seventhcelltext = "EXEC sp_helpsrvrolemember 'sysadmin'"
$eighthcelltext = 'Thats all folks!!
<img src="https://media.giphy.com/media/8P7y2ARUPFpNaaWEZ3/giphy.gif" height="264" title="Windmill">
'
# create the cells
$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 Text -Text $fifthCellText
$sixth = New-ADSWorkBookCell -Type Text -Text $sixthcelltext
$seventh = New-ADSWorkBookCell -Type Code -Text $seventhcelltext
$eighth = New-ADSWorkBookCell -Type Text -Text $eighthcelltext
$path = 'C:\temp\AutoGenerated.ipynb'
# create the notebook
New-ADSWorkBook -Path $path -cells $Intro,$second,$third,$fourth,$fifth,$sixth,$seventh,$eighth
# open the notebook
Invoke-Item $path