Project

PSWriteOffice

PowerShell document automation across OfficeIMO's document, spreadsheet, presentation, PDF, Project, Access, EPUB, invoicing, and conversion engines.

Stars 654
Forks 82
Open issues 1
Total downloads 4,320,051
Release OfficeIMO-v3.5.3
Language: C# Updated: 2026-11-03
Cmdlet

Invoke-OfficeExcelSort

Aliases: ExcelSort
Module
PSWriteOffice
Aliases
ExcelSort
Inputs
OfficeIMO.Excel.ExcelDocument

Sorts the used range on the current worksheet.

Syntax

Invoke-OfficeExcelSort
[-Descending]
[-Header] <String>
[-PassThru]
[<CommonParameters>]
#
Parameter set: ContextSingle
Invoke-OfficeExcelSort
[-Descending]
-Document <ExcelDocument>
[-Header] <String>
[-PassThru]
[-Sheet <String>]
[-SheetIndex <Int32>]
[<CommonParameters>]
#
Parameter set: DocumentSingle
Invoke-OfficeExcelSort
-Document <ExcelDocument>
-Order <Hashtable>
[-PassThru]
[-Sheet <String>]
[-SheetIndex <Int32>]
[<CommonParameters>]
#
Parameter set: DocumentOrder
Invoke-OfficeExcelSort
-Order <Hashtable>
[-PassThru]
[<CommonParameters>]
#
Parameter set: ContextOrder

Examples

Sort by a single header.

ExcelSheet 'Data' { Invoke-OfficeExcelSort -Header 'Name' }

Sorts by the Name column in ascending order.

Sort by multiple headers in order.

$order = [ordered]@{ Status = $true; Total = $false }\nExcelSheet 'Data' { Invoke-OfficeExcelSort -Order $order }

Sorts by Status ascending, then Total descending.

Parameters

-Descending SwitchParameter optionalsets: ContextSingle, DocumentSingle
Sort descending (single-column sort).
-Header String requiredposition: 0sets: ContextSingle, DocumentSingle
Header to sort by (single-column sort).
-PassThru SwitchParameter optional
Emit the worksheet after sorting.
-Document ExcelDocument requiredpipeline: True (ByValue)sets: DocumentSingle, DocumentOrder
Workbook to operate on outside the DSL context.
-Sheet String optionalsets: DocumentSingle, DocumentOrder
Worksheet name when using Document.
-SheetIndex Int32 optionalsets: DocumentSingle, DocumentOrder
Worksheet index (0-based) when using Document.
-Order Hashtable requiredsets: DocumentOrder, ContextOrder
Ordered dictionary of header => ascending (true/false).

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.