Cmdlet
Invoke-OfficeNotebook
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:
PathInvoke-OfficeNotebook
[-AllowLoss]
[-CellIndex <Int32[]>]
[-ContinueOnError]
[-IncludeUnspecifiedLanguage]
-LiteralPath <String>
[-NoClobber]
[-OutputPath <String>]
[-PowerShellPath <String>]
[-StreamOutput]
[-TimeoutSeconds <Int32>]
[-WorkingDirectory <String>]
[<CommonParameters>]#Parameter set:
LiteralPathInvoke-OfficeNotebook
[-AllowLoss]
[-CellIndex <Int32[]>]
[-ContinueOnError]
-Document <NotebookDocument>
[-IncludeUnspecifiedLanguage]
[-NoClobber]
[-OutputPath <String>]
[-PowerShellPath <String>]
[-StreamOutput]
[-TimeoutSeconds <Int32>]
[-WorkingDirectory <String>]
[<CommonParameters>]#Parameter set:
DocumentDescription
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 15Parameters
- -AllowLoss SwitchParameter
- Accept loss reported when normalizing imported content for the .ipynb output.
- -CellIndex Int32[]
- Zero-based cell indexes. Selected PowerShell cells run in notebook order.
- -ContinueOnError SwitchParameter
- Continue after PowerShell cell errors. A timeout or lost session stops execution.
- -IncludeUnspecifiedLanguage SwitchParameter
- Run cells without a declared cell or notebook language as PowerShell.
- -NoClobber SwitchParameter
- Refuse to replace an existing output file.
- -OutputPath String
- 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
- Path to one native .ipynb notebook. FileSystem wildcards must resolve to a single file.
- -PowerShellPath String
- Literal path to a PowerShell executable. The default uses the installed executable for this host when available.
- -StreamOutput SwitchParameter
- Write live output records to the pipeline before the final execution report.
- -TimeoutSeconds Int32
- Maximum seconds per cell. The default is 60. Set to 0 to run without a per-cell timeout.
- -WorkingDirectory String
- Initial working directory. The default uses the notebook's directory when available.
- -LiteralPath String
- Literal .ipynb path, including a FileInfo.FullName or provider PSPath from the pipeline.
- -Document NotebookDocument
- 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.