How to Split Large File in PowerShell

John Wachira Feb 02, 2024
  1. Split a Large File in PowerShell
  2. Use the PowerShell File-Splitter Module to Split a Large File in PowerShell
How to Split Large File in PowerShell

This article demonstrates how we can split large files into smaller chunks with Windows PowerShell.

Split a Large File in PowerShell

Operating with large files can be rather strenuous for most systems. Take, for example, Visual Studio Code. If you have a 300MB text file, VSCode will take a few minutes to load the file.

Splitting the file will make it easier for the program and more manageable.

Let’s say we have a 32MB myfile.txt file, and we wish to split the file into smaller 5MB files. How would we go about it?

Use the PowerShell File-Splitter Module to Split a Large File in PowerShell

PowerShell has various modules that allow users to manipulate files. There exists a File-Splitter module that we can use to break up files into smaller files with a specified file size.

You can also join files with the same module. To use the File-Splitter module, you will need to install it.

Open the PowerShell terminal and run it as administrator. Use the command below to install the File-Splitter module:

Install-Module -Name FileSplitter

PowerShell will prompt you to provide permission to install the module from an untrusted repo.

install module

Type Y to install the module from PSGallery. We are now all set to split our file.

Here is the syntax of the module:

Spli-File <path-to-file> -PartSizeBytes <specifiy file resulting file size>

The Split-File function requires an input parameter, the full path for the file we wish to split. It also accepts the PartSizeBytes parameter, which specifies the resulting size of the split parts.

To split our myfile.txt file, we will run the comma illustrated below:

Split-File C:\Users\pc\Demo\myfile.txt -PartsizeBytes 5mb

This command will split our 30MB myfile.txt into smaller 5MB files. We can run the Get-ChildItem cmdlet to confirm our case:

split files

In a nutshell, the File-Splitter module allows us to split large files into smaller files. You can specify the file size of the resulting parts.

The module works better than Get-Content-based functions, which take up a lot of staging space and splitting time, especially if you are dealing with large files (1GB and above).

Author: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.

LinkedIn

Related Article - PowerShell File