Project

PSWriteOffice

PowerShell document automation across Word, Excel, PowerPoint, PDF, Reader, Confluence, Visio, and open text formats.

Stars 159
Forks 14
PowerShell Gallery downloads 158,661
Release v3.0.5
Language: C# Updated: 2026-09-03

API Reference

Cmdlet

Protect-OfficeWordDocument

Namespace PSWriteOffice
Inputs
OfficeIMO.Word.WordDocument

Protects a Word document with a password.

Remarks

Sets the protection password and the protection type (default: ReadOnly).

Examples

Authored help example

Protect a generated document as read-only.

PS>


New-OfficeWord -Path .\ProtectedReport.docx {
                Add-OfficeWordParagraph -Text 'Confidential report'
                Protect-OfficeWordDocument -Password 'secret' -ProtectionType ReadOnly
            }
        

Sets OfficeIMO.Word document protection while the document is being composed.

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.

Syntax

Protect-OfficeWordDocument [-Document <WordDocument>] [-PassThru] -Password <String> [-ProtectionType <ReadOnly|Comments|TrackedChanges|Forms>] [<CommonParameters>]
#
Parameter set: All Parameter Sets

Parameters

Document WordDocument optionalposition: namedpipeline: True (ByValue)
Document to protect when provided explicitly.
PassThru SwitchParameter optionalposition: namedpipeline: False
Emit the protected document.
Password String requiredposition: 0pipeline: False
Password to apply.
ProtectionType WordDocumentProtectionType optionalposition: namedpipeline: Falsevalues: 4
Protection type (defaults to ReadOnly).
Possible values: ReadOnly, Comments, TrackedChanges, Forms