Choose a PSWriteOffice Workflow
Edit on GitHubDecide between authoring, editing, inspection, conversion, and normalized Reader extraction. Includes examples and cmdlet links.
PSWriteOffice exposes several paths that can reach the same file format. Choosing the path by outcome keeps scripts smaller and makes failure handling clearer. See pipeline, object, and DSL workflows for copyable examples of each style.
Export rows directly
Use the pipeline for a simple data export. It is the shortest route from PowerShell objects, database results, or API responses to a workbook:
$rows | Export-OfficeExcel -Path '.\Report.xlsx' -Sheet 'Data' -TableName 'Data'
Move to the object or DSL surface only when the output needs more structure.
Create a new artifact
Use the document DSL when the script owns the output from the beginning. New-OfficeWord, New-OfficeExcel, New-OfficePowerPoint, New-OfficePdf, and New-OfficeVisio accept script blocks that describe the document. The outer command owns creation and final save; nested commands add content to the active document context.
This path works well for scheduled reports, build artifacts, exports, invoices, runbooks, and operational dashboards.
Build incrementally with document objects
Leave out the content block on New-OfficeWord, New-OfficeExcel, New-OfficePowerPoint, New-OfficePdf or New-OfficeMarkdown when loops and conditions need a live document. Add content through explicit -Document, -Worksheet, -Document, -Slide, or pipeline targets, then save once. This is also the natural migration path for scripts that previously held a PSWriteWord or PSWriteExcel document variable.
Load and change an existing file
Use the matching Open-Office* command to open the document, target specific content with Find-* or Get-*, apply Set-*, Update-*, Add-*, or Remove-* operations, and finish with the matching Save-* command.
Keep mutation explicit. A useful script shape is:
- inspect the input and collect diagnostics;
- decide whether the requested change is safe;
- apply a bounded set of changes;
- save to a new path during validation;
- compare or reopen the result.
Inspect without changing
Use inspection and preflight commands when the job needs evidence rather than a rewritten file. Use Get-OfficeDocumentInfo -Detailed for native snapshots, Test-OfficeDocument for document checks, New-OfficeExcelTestOptions for workbook capability checks, and Get-OfficePdfDiagnostic for PDF evidence.
Inspection-first workflows are appropriate for inventory, compliance gates, support diagnostics, and deciding which conversion route to use. Get-OfficeDocumentCapability -Protection lists supported protection operations; -Conversion -From Word -To Pdf lists conversion contracts.
Normalize many formats
Use New-OfficeDocumentReader with Read-OfficeDocument when downstream code should not branch on every source format. Select chunks, hierarchy, structured data, tables, visuals, assets, or ingestion summaries with -As. Get-OfficeDocumentInfo handles detection and inspection.
Choose the format-specific family instead when the script must edit native features that the normalized model intentionally does not preserve.
Convert and review
Use Convert-OfficeDocument when the destination format is the outcome. HTML review commands are useful for browser-based review; Markdown is useful for source control and text pipelines; PDF is useful for fixed-layout delivery. Conversion can be loss-aware rather than lossless, so inspect diagnostics for complex documents and retain the source artifact.