This PowerShell script allows you to split large .csv files into smaller, manageable chunks based on either file size (for CSV output) or row count (for Excel .xlsx output). Itβs designed for speed, flexibility, and usabilityβideal for data processing, archiving, or sharing.
- Console-only interaction (no GUI prompts)
- Select any folder containing
.csvfiles - Choose output format:
.csvor.xlsx - Streamed writing for CSV (fast and memory-efficient)
- Excel export via ImportExcel
- Configurable chunk size (MB) or row limit
- Optional header inclusion in each chunk
- Timestamped output folder for easy organization
- Progress tracking and summary display
- Windows PowerShell 5.1 or PowerShell Core
- ImportExcel module (only required for
.xlsxoutput)
To install ImportExcel:
Install-Module -Name ImportExcel -Scope CurrentUser- Output files are saved in a subfolder named like:
filename_split_YYYYMMDD_HHMMSS - Files are named:
filename_chunk_1.csv,filename_chunk_2.xlsx, etc.
Run the script in PowerShell and follow the prompts:
PS> .\Split-Csv.ps1
'''
Example interaction:
Enter folder path containing CSV files (press Enter for Desktop): C:\Data
Enter the number of the file to split: 1
Do you want the output files in Excel XLSX format? (Y/N): Y
Enter max number of rows per Excel file (default is 50000): 25000
Include headers in each chunk? (Y/N, default is Y): Y
β
Splitting complete!
Chunks created: 12
Saved to: C:\Data\sales_data_split_20250910_1045| Parameter | Description | Default |
|---|---|---|
chunkSizeMB |
Max size per CSV chunk (in megabytes) | 100 |
maxRowsPerChunk |
Max rows per Excel chunk | 50000 |
includeHeaders |
Include header row in each chunk | Yes |
MIT License
Created by David Reynolds
Excel export powered by ImportExcel