# Invoke-OfficeNotebook

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

Cmdlet 

**Module**

`PSWriteOffice`

**Inputs**

`OfficeIMO.Notebook.NotebookDocument` `System.String`

**Outputs**

`OfficeIMO.Notebook.PowerShell.NotebookExecutionReport` `OfficeIMO.Notebook.PowerShell.NotebookExecutionEvent`

**Source**

[InvokeOfficeNotebookCommand.cs:35](https://github.com/EvotecIT/OfficeIMO/blob/e5095b350a92a5a1ced361fa9b0c5c946a2cbdaf/PowerShell/PSWriteOffice/Sources/PSWriteOffice/Cmdlets/Notebook/InvokeOfficeNotebookCommand.cs#L35) 

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>]
```

[#](#method-invoke-officenotebook-switchparameter-int32-switchparameter-switchparameter-switchparameter-string-string-string-switchparameter-int32-string)

Parameter set: `Path`

```
Invoke-OfficeNotebook
[-AllowLoss]
[-CellIndex <Int32[]>]
[-ContinueOnError]
[-IncludeUnspecifiedLanguage]
-LiteralPath <String>
[-NoClobber]
[-OutputPath <String>]
[-PowerShellPath <String>]
[-StreamOutput]
[-TimeoutSeconds <Int32>]
[-WorkingDirectory <String>]
[<CommonParameters>]
```

[#](#method-invoke-officenotebook-switchparameter-int32-switchparameter-switchparameter-string-switchparameter-string-string-switchparameter-int32-string)

Parameter set: `LiteralPath`

```
Invoke-OfficeNotebook
[-AllowLoss]
[-CellIndex <Int32[]>]
[-ContinueOnError]
-Document <NotebookDocument>
[-IncludeUnspecifiedLanguage]
[-NoClobber]
[-OutputPath <String>]
[-PowerShellPath <String>]
[-StreamOutput]
[-TimeoutSeconds <Int32>]
[-WorkingDirectory <String>]
[<CommonParameters>]
```

[#](#method-invoke-officenotebook-switchparameter-int32-switchparameter-notebookdocument-switchparameter-switchparameter-string-string-switchparameter-int32-string)

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.

## Guides & Samples

Authored walkthroughs and practical samples linked to this command.

- [Reliable Automation Patterns](/docs/pswriteoffice/automation-patterns/) Guide
  
  Structure document jobs for repeatability, diagnostics, safe mutation, and CI artifacts. Includes examples and cmdlet links.

## Examples

### Run PowerShell cells and save a separate notebook.

```powershell
$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.

```powershell
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.

```powershell
$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](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_commonparameters).

<!-- PowerForge markdown artifact sha256:5B84C165B9235D3D6496294EC1FA9D88E562917F24B0948267B15C9CEC1F31F4 -->
