# Invoke-OfficeExcelSort

Sorts the used range on the current worksheet. Review available syntax, parameters, pipeline guidance, and reference details in PSWriteOffice API Reference.

Project

PSWriteOffice

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

[View on GitHub](https://github.com/EvotecIT/OfficeIMO/tree/master/PowerShell/PSWriteOffice) [Visit Website](#) [Releases](https://github.com/EvotecIT/PSWriteOffice/releases/tag/v3.0.5) [Changelog](#) [Get package](https://www.powershellgallery.com/packages/PSWriteOffice/0.2.0)

Stars **722**

Forks **84**

Open issues **2**

Total downloads **5,184,525**

Release **OfficeIMO-v3.6.2**

Language: C# Updated: 2026-11-22

Cmdlet 

Aliases: ExcelSort

**Module**

`PSWriteOffice`

**Aliases**

`ExcelSort`

**Inputs**

`OfficeIMO.Excel.ExcelDocument`

**Source**

[InvokeOfficeExcelSortCommand.cs:25](https://github.com/EvotecIT/PSWriteOffice/blob/main/Sources/PSWriteOffice/Cmdlets/Excel/InvokeOfficeExcelSortCommand.cs#L25) 

Sorts the used range on the current worksheet.

## Syntax

```
Invoke-OfficeExcelSort
[-Descending]
[-Header] <String>
[-PassThru]
[<CommonParameters>]
```

[#](#method-invoke-officeexcelsort-switchparameter-string-switchparameter)

Parameter set: `ContextSingle`

```
Invoke-OfficeExcelSort
[-Descending]
-Document <ExcelDocument>
[-Header] <String>
[-PassThru]
[-Sheet <String>]
[-SheetIndex <Int32>]
[<CommonParameters>]
```

[#](#method-invoke-officeexcelsort-switchparameter-exceldocument-string-switchparameter-string-int32)

Parameter set: `DocumentSingle`

```
Invoke-OfficeExcelSort
-Document <ExcelDocument>
-Order <Hashtable>
[-PassThru]
[-Sheet <String>]
[-SheetIndex <Int32>]
[<CommonParameters>]
```

[#](#method-invoke-officeexcelsort-exceldocument-hashtable-switchparameter-string-int32)

Parameter set: `DocumentOrder`

```
Invoke-OfficeExcelSort
-Order <Hashtable>
[-PassThru]
[<CommonParameters>]
```

[#](#method-invoke-officeexcelsort-hashtable-switchparameter)

Parameter set: `ContextOrder`

## Examples

### Sort by a single header.

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

Sorts by the Name column in ascending order.

### Sort by multiple headers in order.

```powershell
$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](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_commonparameters).

Evotec API Reference Copyright 2026 Evotec Services

<!-- PowerForge markdown artifact sha256:3842C85997E4355A3E55171277E22D2426E7AECB6AE6AE42153C8DF09130CB6F -->
