Home
Manage Your Code
Snippet: Generate Test Files with PowerShell (PowerShell)
Title: Generate Test Files with PowerShell Language: PowerShell
Description: Creates N number of test files of a specific size. You can control where the files are created, how many to create and the size to create them. You can also control what filler character is used to file the file. Views: 977
Author: Michael Wood Date Added: 7/4/2008
Copy Code  
function Create-TestFile([string]$location, [long]$sizeInBytes, [int]$numberOfFiles = 1 ,[char]$fillerChar="X")
{
$fc = new-object string ($fillerChar, $sizeInBytes ) ;
1..$numberOfFiles | %{ [io.file]::WriteAllText("$location\TestFile-$_.txt", $fc) }
}
Usage
Create-TestFile "C:\temp" 2100 #creates a file 2100 bytes in size.
Notes
Modified from example at : http://www.winterdom.com/weblog/2008/04/09/GeneratingFilesWithPowerShell.aspx