Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Protect-OfficeExcelWorkbook

Aliases: ExcelWorkbookProtect
Module PSWriteOffice
Aliases
ExcelWorkbookProtect
Inputs
OfficeIMO.Excel.ExcelDocument
Outputs
OfficeIMO.Excel.ExcelDocument System.IO.FileInfo

Protects workbook structure or windows metadata. This is not file encryption.

Syntax

Protect-OfficeExcelWorkbook [-LegacyPasswordHash <String>] [-NoStructure] [-PassThru] [-Password <String>] [-ProtectWindows] [<CommonParameters>]
#
Parameter set: Context
Protect-OfficeExcelWorkbook [-LegacyPasswordHash <String>] [-NoStructure] [-PassThru] [-Password <String>] [-Path] <String> [-ProtectWindows] [<CommonParameters>]
#
Parameter set: Path
Protect-OfficeExcelWorkbook -Document <ExcelDocument> [-LegacyPasswordHash <String>] [-NoStructure] [-PassThru] [-Password <String>] [-ProtectWindows] [<CommonParameters>]
#
Parameter set: Document

Examples

Authored help example

Prevent worksheet add/delete/move/rename operations in Excel UI.

Protect-OfficeExcelWorkbook -Path .\Report.xlsx -Password secret
Test-OfficeExcelWorkbook -Path .\Report.xlsx -SkipOpenXmlValidation |
    Select-Object Passed, ProtectionSummary

Writes workbook-level structure protection metadata and saves the workbook.

Parameters

-LegacyPasswordHash String optional
Optional precomputed legacy workbook protection hash to write as-is.
-NoStructure SwitchParameter optional
Do not protect workbook structure.
-PassThru SwitchParameter optional
Emit the workbook after protection.
-Password String optional
Optional workbook protection password. This is UI protection, not package encryption.
-ProtectWindows SwitchParameter optional
Protect workbook windows where supported by the consuming application.
-Path String requiredposition: 0aliases: FilePath, InputPathsets: Path
Workbook path to update.
-Document ExcelDocument requiredpipeline: True (ByValue)sets: Document
Workbook to update outside the DSL context.

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.