PowerShell: SharePoint - Populate a Document Library

Updated on 5/29/2013

$webName = "http://dmg-10"; 
$docLibName = "Shared Documents"; 
$docFileName = "c:\test.txt"; 
$docCount = 1000; 

$web = Get-SPWeb -Identity $webName; 
$docLib = $web.Lists[$docLibName]; 
$folder = $docLib.RootFolder; 
$docFileInfo = Get-Item $docFileName; 

$fileStream = $docFileInfo.OpenRead(); 
$contents = new-object byte[] $fileStream.Length; 
$bytesRead = $fileStream.Read($contents, 0, [int]$fileStream.Length); 
$fileStream.Close(); 

for ($i = 0; $i -lt $docCount; $i++) 
{ 
	$spFile = $folder.Files.Add($folder.Url + "/" + $i + $docFileInfo.Extension, $contents, $true); 
	$spItem = $spFile.Item; 
	$spItem.Update(); 
}