PowerShell Append 2mb of Junk to a .txt file

# Specify the path to the existing text file
$filePath = "C:\TEMP\Rubbish.txt"

# Calculate the size of 2MB in bytes
$additionalDataSize = 2 * 1024 * 1024

# Generate 2MB of random data
$randomText = [byte[]]::new($additionalDataSize)

$random = New-Object System.Random
$random.NextBytes($randomText)

# Open the file in append mode and write the random data
$fileStream = [System.IO.File]::Open($filePath, [System.IO.FileMode]::Append)
$fileStream.Write($randomText, 0, $randomText.Length)
$fileStream.Close()

Write-Host "Added 2MB of random data to $filePath"

Leave a Reply

Your email address will not be published. Required fields are marked *