forked from dfinke/PowerShellNotebook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetNotebook.ps1
More file actions
68 lines (56 loc) · 3.13 KB
/
Copy pathGetNotebook.ps1
File metadata and controls
68 lines (56 loc) · 3.13 KB
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
61
62
63
64
65
66
67
68
function Get-Notebook {
<#
.SYNOPSIS
Get-Notebook reads the metadata of a single (or folder of) Jupyter Notebooks
.Example
Get-Notebook .\samplenotebook\Chapter01code.ipynb
NoteBookName : Chapter01code.ipynb
KernelName : powershell
CodeBlocks : 83
MarkdownBlocks : 23
NoteBookFullName : C:\Users\Douglas\Documents\GitHub\MyPrivateGit\PowerShellNotebook\samplenotebook\Chapter01code.ipynb
.Example
Get-Notebook .\samplenotebook\| Format-Table
NoteBookName KernelName CodeBlocks MarkdownBlocks NoteBookFullName
------------ ---------- ---------- -------------- ----------------
Chapter01code.ipynb powershell 83 23 C:\Users\Douglas\Documents\GitHub\MyPrivateGit\Power...
csharp.ipynb .net-csharp 1 0 C:\Users\Douglas\Documents\GitHub\MyPrivateGit\Power...
fsharp.ipynb .net-fsharp 1 0 C:\Users\Douglas\Documents\GitHub\MyPrivateGit\Power...
powershell.ipynb .net-powershell 1 0 C:\Users\Douglas\Documents\GitHub\MyPrivateGit\Power...
python.ipynb python3 1 0 C:\Users\Douglas\Documents\GitHub\MyPrivateGit\Power...
SingleCodeBlock.ipynb powershell 1 0 C:\Users\Douglas\Documents\GitHub\MyPrivateGit\Power
.Example
dir -Filter *.ipynb -Recurse | foreach {
Get-Notebook -Path $_.FullName } |
group KernelName
Count Name Group
----- ---- -----
98 powershell {@{NoteBookName=Aaron_CopyWorkspace.ipynb; KernelName=powershell; CodeBlocks=14; Mar...
2 not found {@{NoteBookName=BPCheck.ipynb; KernelName=not found; CodeBlocks=0; MarkdownBlocks=0;...
36 SQL {@{NoteBookName=BPCheck.ipynb; KernelName=SQL; C...
29 python3 {@{NoteBookName=python install powershell_kernel.ipynb; KernelName=python3; CodeBloc...
781 .net-powershell {@{NoteBookName=Using_ConvertTo-SQLNoteBook.ipynb; KernelName=.net-powershell; CodeB...
3 pyspark3kernel {@{NoteBookName=load-sample-data-into-bdc.ipynb; KernelName=pyspark3kernel; C...
This command will allow you to serch through a directory & all sub directories to find Jupyter Notebooks & group them by Kernel used in each of those Notebook.
#>
param(
$Path,
$NoteBookName
)
if (!$Path) { $Path = "." }
if (!$NoteBookName) { $NoteBookName = '*' }
$targetName = "$($NotebookName).ipynb"
foreach ($file in Get-ChildItem $Path $targetName) {
$r = Get-Content $file.fullname | ConvertFrom-Json
$kernelspecName = $r.metadata.kernelspec.name
if (!$kernelspecName) { $kernelspecName = "not found" }
$counts = $r.cells | Group-Object cell_type -AsHashTable
[PSCustomObject][Ordered]@{
NoteBookName = $file.Name
KernelName = $kernelspecName
CodeBlocks = $counts.code.Count
MarkdownBlocks = $counts.markdown.Count
NoteBookFullName = $file.FullName
}
}
}