Cmdlet
Protect-OfficeExcelSheet
Protects a worksheet and chooses what users may still do.
Syntax
Protect-OfficeExcelSheet
[-AllowAutoFilter]
[-AllowDeleteColumns]
[-AllowDeleteRows]
[-AllowFormatCells]
[-AllowFormatColumns]
[-AllowFormatRows]
[-AllowInsertColumns]
[-AllowInsertHyperlinks]
[-AllowInsertRows]
[-AllowPivotTables]
[-AllowSort]
[-AllowTableEditing]
[-Document <ExcelDocument>]
[-NoSelectLockedCells]
[-NoSelectUnlockedCells]
[-PassThru]
[-Password <SecureString>]
[-Sheet <OfficeSheetSelector>]
[<CommonParameters>]#Parameter set:
DefaultExamples
Protect a sheet
Open-OfficeExcel -Path .\Finance\Pricing-Model.xlsx {
Protect-OfficeExcelSheet -Sheet Inputs
}Locks the Inputs sheet so only unlocked cells can be edited.
Protect a shared list but keep it usable
Open-OfficeExcel -Path .\HR\Staff-Directory.xlsx {
ExcelSheet 'Directory' {
Protect-OfficeExcelSheet -AllowSort -AllowAutoFilter -AllowFormatColumns
}
}Protects the staff list while still letting colleagues sort, filter and resize columns.
Protect a sheet with a password
$password = Read-Host -Prompt 'Sheet password' -AsSecureString
Open-OfficeExcel -Path .\Finance\Pricing-Model.xlsx {
Protect-OfficeExcelSheet -Sheet Inputs -Password $password -AllowSort -AllowAutoFilter
}Locks the input sheet with a password read from the console, still allowing sorting and filtering.
Parameters
- -AllowAutoFilter SwitchParameter
- Allow AutoFilter.
- -AllowDeleteColumns SwitchParameter
- Allow deleting columns.
- -AllowDeleteRows SwitchParameter
- Allow deleting rows.
- -AllowFormatCells SwitchParameter
- Allow formatting cells.
- -AllowFormatColumns SwitchParameter
- Allow formatting columns.
- -AllowFormatRows SwitchParameter
- Allow formatting rows.
- -AllowInsertColumns SwitchParameter
- Allow inserting columns.
- -AllowInsertHyperlinks SwitchParameter
- Allow inserting hyperlinks.
- -AllowInsertRows SwitchParameter
- Allow inserting rows.
- -AllowPivotTables SwitchParameter
- Allow PivotTables.
- -AllowSort SwitchParameter
- Allow sorting.
- -AllowTableEditing SwitchParameter
- Allow common protected-table workflows: selecting cells, inserting rows, sorting, and filtering.
- -Document ExcelDocument
- Caller-owned workbook; omission uses the enclosing Excel content block.
- -NoSelectLockedCells SwitchParameter
- Prevents selecting locked cells while the worksheet is protected.
- -NoSelectUnlockedCells SwitchParameter
- Prevents selecting unlocked cells while the worksheet is protected.
- -PassThru SwitchParameter
- Emits the native result after the operation.
- -Password SecureString
- Password used to open an encrypted workbook package.
- -Sheet OfficeSheetSelector
- Worksheet name, one-based position or native worksheet object. Multi-sheet commands also accept wildcard names.
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.