Notice: Due to size constraints and loading performance considerations, scripts referenced in blog posts are not attached directly. To request access, please complete the following form: Script Request Form Note: A Google account is required to access the form.
Disclaimer: I do not accept responsibility for any issues arising from scripts being run without adequate understanding. It is the user's responsibility to review and assess any code before execution. More information

Powershell : Splitting a large file into smaller ones....


Ever needed to split a large list into smaller files? Here's a simple PowerShell script that does exactly that.

The Problem

You have a text file with thousands of domains, and you need to break it into smaller chunks. Maybe for transport rules, parallel processing, or just to make it more manageable.

The Solution

This script takes your big domain list and splits it into equal parts:

# Full path to the original domain list
$inputFile = "domains.txt"

# Output folder (must exist)
$outputFolder = "C:\temp\SplitOutput"

# Read all domains (trim whitespace, ignore empty lines)
$domains = Get-Content $inputFile | Where-Object { $_.Trim() -ne "" }

# Number of files to split into
$splitCount = 4

# Calculate number of lines per file
$perFile = [Math]::Ceiling($domains.Count / $splitCount)

# Split and write to files
for ($i = 0; $i -lt $splitCount; $i++) {
    $startIndex = $i * $perFile
    $chunk = $domains[$startIndex..([Math]::Min($startIndex + $perFile - 1, $domains.Count - 1))]

    $outputFile = Join-Path $outputFolder "senders_part$($i + 1).txt"
    $chunk | Set-Content $outputFile
    Write-Host "Created $outputFile with $($chunk.Count) domains"
}

What It Does

  1. Reads your domain list file
  2. Removes empty lines and extra spaces
  3. Calculates how many domains per file
  4. Creates the split files with names like senders_part1.txt, senders_part2.txt, etc.
  5. Shows you what it created

How to Use It

  1. Put your domain list in domains.txt
  2. Make sure the output folder exists
  3. Change $splitCount if you want more or fewer files
  4. Run the script

That's it. Your big list is now split into manageable chunks, ready to use however you need them.

Previous Post Next Post

نموذج الاتصال