09 May 2012 @ 9:16 AM 

Sometimes, when I demonstrate the ease and strength of PowerShell to a customer, I need to quickly generate some fake files en directory structure… also those files have to be from different sizes. For this, I’ve created the following script:

function New-DemoData ($Path)
{
  # Usage: New-DemoData “D:\Company”
  Push-Location
  1..10 | % { Set-Location -Path (New-Item -ItemType directory -path "$path\$_").fullname -ErrorAction SilentlyContinue
  for ( $i=1; $i -le (Get-Random -Minimum 10 -Maximum 200); $i++ )
    {
      fsutil file createnew ("File" + $i + ".txt") (Get-Random -Minimum 1024 -Maximum 819200)
    }
  }
  Pop-Location
}

This script will create 10 folders (named 1-10) at the target path (provided by the parameter) and create a random number of *.txt files (between 10 and 200) in each directory, each file between 1KB and 800KB in size.

Post to Twitter

Posted By: Jeff Wouters
Last Edit: 09 May 2012 @ 09:16 AM

EmailPermalink
Tags
Categories: PowerShell, Script



 Last 50 Posts
 Back
Change Theme...
  • Users » 1
  • Posts/Pages » 251
  • Comments » 430
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

About



    No Child Pages.

Contact



    No Child Pages.