Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Invoke-OfficeNotebook

Module
PSWriteOffice
Inputs
OfficeIMO.Notebook.NotebookDocument System.String
Outputs
OfficeIMO.Notebook.PowerShell.NotebookExecutionReport OfficeIMO.Notebook.PowerShell.NotebookExecutionEvent

Runs selected PowerShell notebook cells in one persistent session and records their outputs.

Syntax

Invoke-OfficeNotebook
[-AllowLoss]
[-CellIndex <Int32[]>]
[-ContinueOnError]
[-IncludeUnspecifiedLanguage]
[-NoClobber]
[-OutputPath <String>]
[-Path] <String>
[-PowerShellPath <String>]
[-StreamOutput]
[-TimeoutSeconds <Int32>]
[-WorkingDirectory <String>]
[<CommonParameters>]
#
Parameter set: Path
Invoke-OfficeNotebook
[-AllowLoss]
[-CellIndex <Int32[]>]
[-ContinueOnError]
[-IncludeUnspecifiedLanguage]
-LiteralPath <String>
[-NoClobber]
[-OutputPath <String>]
[-PowerShellPath <String>]
[-StreamOutput]
[-TimeoutSeconds <Int32>]
[-WorkingDirectory <String>]
[<CommonParameters>]
#
Parameter set: LiteralPath
Invoke-OfficeNotebook
[-AllowLoss]
[-CellIndex <Int32[]>]
[-ContinueOnError]
-Document <NotebookDocument>
[-IncludeUnspecifiedLanguage]
[-NoClobber]
[-OutputPath <String>]
[-PowerShellPath <String>]
[-StreamOutput]
[-TimeoutSeconds <Int32>]
[-WorkingDirectory <String>]
[<CommonParameters>]
#
Parameter set: Document

Description

Run notebooks whose code you trust. The child PowerShell process runs under your account. The returned report contains the updated live notebook. Close the notebook when you finish using it.

Use -WhatIf to preview execution and any requested save. Use -Confirm to ask before running the notebook.

Examples

Run PowerShell cells and save a separate notebook.

$report = Invoke-OfficeNotebook -LiteralPath ./lab.ipynb -OutputPath ./executed.ipynb -NoClobber
if ($null -ne $report) {
    try {
        $report.Cells
    } finally {
        $report.Notebook | Close-OfficeNotebook
    }
}

Preview execution and ask for confirmation before running.

Invoke-OfficeNotebook -LiteralPath ./lab.ipynb -OutputPath ./reviewed.ipynb -WhatIf
$report = Invoke-OfficeNotebook -LiteralPath ./lab.ipynb -OutputPath ./reviewed.ipynb -Confirm
if ($null -ne $report) {
    $report.Notebook | Close-OfficeNotebook
}

Run two selected cells in a live notebook.

$notebook | Invoke-OfficeNotebook -CellIndex 0, 2 -TimeoutSeconds 15

Parameters

-AllowLoss SwitchParameter optional
Accept loss reported when normalizing imported content for the .ipynb output.
-CellIndex Int32[] optional
Zero-based cell indexes. Selected PowerShell cells run in notebook order.
-ContinueOnError SwitchParameter optional
Continue after PowerShell cell errors. A timeout or lost session stops execution.
-IncludeUnspecifiedLanguage SwitchParameter optional
Run cells without a declared cell or notebook language as PowerShell.
-NoClobber SwitchParameter optional
Refuse to replace an existing output file.
-OutputPath String optional
Atomically save the executed notebook to this .ipynb path, including any partial results reported after a cell error or timeout. Use this parameter with one notebook per invocation.
-Path String requiredposition: 0pipeline: True (ByValue)sets: Path
Path to one native .ipynb notebook. FileSystem wildcards must resolve to a single file.
-PowerShellPath String optional
Literal path to a PowerShell executable. The default uses the installed executable for this host when available.
-StreamOutput SwitchParameter optional
Write live output records to the pipeline before the final execution report.
-TimeoutSeconds Int32 optional
Maximum seconds per cell. The default is 60. Set to 0 to run without a per-cell timeout.
-WorkingDirectory String optional
Initial working directory. The default uses the notebook's directory when available.
-LiteralPath String requiredpipeline: True (ByPropertyName)aliases: FullName, PSPathsets: LiteralPath
Literal .ipynb path, including a FileInfo.FullName or provider PSPath from the pipeline.
-Document NotebookDocument requiredpipeline: True (ByValue)sets: Document
Live notebook to update with the execution results.

Common Parameters

This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.

For more information, see about_CommonParameters.