How often have you worked on a project were you needed to create random files in big quantity in order to simulate a data usage ?

On some projects you might just need one or two big files, simply to measure bandwidth, or validate a backup procedure for example. On the next project, you might  need to create random files  to test a migration script and need a huge number of small files.

How do I create random files with human understandable names using PowerShell?

Well, i was facing that situation the other day, and started to write a function in order to create random files  with “humanly understandable” names. (and sometimes even funny names if you are lucky ;))

Find here the code for the function “Create-randomFiles” which will help you, well, create random files using powershell, and answer the scenarios above.

By | 2016-06-28T10:28:23+00:00 August 8th, 2012|Files and folders, Functions, PowerShell|7 Comments

About the Author:

Stéphane is a dynamic and passionate Cloud and datacenter Microsoft MVP since. He is the founder of the Basel PowerShell user Group (BPUG), the co-founder of the French Speaking PowerShell UserGroup (FRPSUG), author, blogger, and received the community award "PowerShell Hero" from Stéphane has implemented microsoft infrastructure solutions in various countries of Europe and is currently working in Basel / Switzerland. Stéphane help his clients to reduce their global infrastructure costs by implementing Microsft infrastructure solutions by combining great products such as System Center, Windows Server, with heavy automation using Windows PowerShell. Stéphane loves languages, Belgium beer, French cheese and French Wine. If any of these topics are of your interest, don't hesitate to come and say hi.


  1. rvanraamsdonk August 8, 2018 at 12:25 pm - Reply

    Hi Stephane, I’ve renamed your script to GenerateDummyDocuments.ps1, am trying to run in Windows Powershell as admin, ExecutionPolicy = Unrestricted.

    PS C:\Users\rober\Documents> .\GenerateDummyDocuments.ps1 -Totalsize 50MB -NumberOfFiles 13 -Path C:\Users\rober\Documents

    It does not appear to run, but no errors, returns me to the cursor almost immediately. What am I doing wrong?

    • Stephane August 8, 2018 at 3:06 pm - Reply

      the script contains a function that needs to be dot sourced.
      call the script once using this syntax:
      . .\scriptName.ps1
      then you can call the function “Create-Files” using the parameters you specified.
      let me know if this works for you.

      • rvanraamsdonk August 8, 2018 at 6:01 pm - Reply

        Hi, I got that to work, thanks very much! Learning Powershell as I go…:-) Additional question: the parameters -FilesTypes and -Whatif are not recognized (script errors). I input them as “-FilesTypes Office” (without quotes) and “-Whatif” (again without quotes). Kind regards, Robert

      • f3haskell November 8, 2018 at 4:26 pm - Reply

        I am seeing the same thing that rvanraamsdonk ran into; however, .\Create-RandomFiles.ps1 -TotalSize 50MB -NumberOfFiles 50 -path e:\data

        I attempt to dot source using the following:

        PS D:\scripts> ..\Create-RandomFiles.ps1
        ..\Create-RandomFiles.ps1 : The term ‘..\Create-RandomFiles.ps1’ is not recognized as the name of a cmdlet, function,
        script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
        correct and try again.
        At line:1 char:1
        + ..\Create-RandomFiles.ps1
        + ~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo : ObjectNotFound: (..\Create-RandomFiles.ps1:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException

        I am unsure as to what to do next.

  2. Mark Bond January 1, 2018 at 3:24 pm - Reply

    Hi Stephane,

    I need to test SFTP upload generating 300 PDF files with random sizes from 1mb to 100mb. I am a noob and could not make your code work. Can you help please?

  3. Behrooz Sirouszad November 27, 2017 at 11:25 am - Reply

    it doesnt work on powershell 5 windows server 2016

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: