Home » PowerShell » PowerShell Split File in smaller files

PowerShell Split File in smaller files

PowerShell has multiple modules for file manipulation. It has a File-Splitter module which is used to split file into smaller files based on file size.

The File-Splitter module has functions to split a file into smaller files and join the files.

In this article, we will discuss how to use the File-Splitter module to split a large file into smaller files.

PowerShell File-Splitter Module – Split-File

The File-Splitter module splits the large file into multiple parts based on the file size provided and also joins the parts to create the original file.

Use the below link to read more about the File-Splitter module and the functions available in it.

PowerShell Module: File-Splitter

You will need to install the File-Splitter module if it is not available in the system.

Open the PowerShell terminal with a Run as Administrator. Use the below command to install the module.

Install-Module -Name FileSplitter

It will ask you for permission to install the module from an untrusted repository.

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are
you sure you want to install the modules from 'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): 

If you want to install the module from PSGallary, type Y else N

Cool Tip: How to get file attributes in PowerShell!

PowerShell Split File into Smaller Files

The File-Splitter module has a Split-File function to split a file into smaller parts based on file size.

The Split-File function accepts the file path as an input parameter which will be split into multiple parts and PartSizeBytes to split the file into provided size.

Split-File D:\LogTest\FTP-02\File-Split\LogFile.txt -PartSizeBytes 1MB 

The output of the above PowerShell script will split a large log file into multiple files of size 1MB.

PowerShell Split File into multiple files
PowerShell Split File into multiple files

Use the Get-ChildItem command to get the list of files in the directory.

Conclusion

I hope the above article on how to split the huge file into multiple files using the File-Splitter module is helpful to you.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.

Note: File-Splitter module installation requires accepting the consent to install from an untrusted repository. If you trust the repository source, accept the consent or you can change the installation policy as per your organization’s policy else type N to deny the installation.