-
-
Save 0xAJStrike/67943cbcb7cc7ae68c9ef4de7cfd2f53 to your computer and use it in GitHub Desktop.
Powershell script to create some random files with specified depth and file size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function New-TestData { | |
| [CmdletBinding()] | |
| param ( | |
| [Parameter(Mandatory)] | |
| [ValidateScript({Test-Path $_})] | |
| [String]$RootFolder, | |
| # How many subfolders should be created | |
| [Parameter(Mandatory=$false)] | |
| [int] | |
| $Level = 3, | |
| # Root Elements | |
| [Parameter(Mandatory=$false)] | |
| [String[]] | |
| $FolderNameArr = @("Dep1","Dep2","Dep3"), | |
| # File Count per folder | |
| [Parameter(Mandatory=$false)] | |
| [int] | |
| $FileCount = 32, | |
| # File Extension List | |
| [Parameter(Mandatory=$false)] | |
| [String[]] | |
| $FileExtensionArr = @("txt","csv"), | |
| # String Length | |
| [Parameter(Mandatory=$false)] | |
| [int] | |
| $StringLength = 16 | |
| ) | |
| begin { | |
| function Get-RandomString { | |
| param ( | |
| # String Length | |
| [Parameter(Mandatory=$false)] | |
| [int] | |
| $StringLength = 16 | |
| ) | |
| $arr = 97..122 | |
| $str = "" | |
| 1..$StringLength | ForEach-Object { | |
| $str += [char](Get-Random $arr) | |
| } | |
| return $str | |
| } | |
| } | |
| process { | |
| foreach ($folder in $FolderNameArr) { | |
| $newElement = Join-Path -Path $RootFolder -ChildPath $folder | |
| 1..$Level | ForEach-Object { | |
| $folderName = Get-RandomString -StringLength $StringLength | |
| $newElement = Join-Path -Path $newElement -ChildPath $folderName | |
| if ($_ -eq $Level) { | |
| 1..$FileCount | ForEach-Object { | |
| $newFileName = "$(Get-RandomString)" + "." + "$($FileExtensionArr | Get-Random)" | |
| $newFilePath = Join-Path $newElement -ChildPath $newFileName | |
| #$newFilePath = ($newFilePath -replace 'E:','\\?\E:\\') | |
| #Write-Host $newFilePath | |
| New-Item (split-path -Path $newFilePath -Parent) -ItemType Directory -Force | |
| fsutil file createNew $newFilePath 26214400 | |
| } | |
| } | |
| } | |
| } | |
| } | |
| end { | |
| } | |
| } | |
| #New-TestData -RootFolder E:\Temp\SemperOper2 -Level 3 -StringLength 256 | |
| New-TestData -RootFolder E:\CloudSync -Level 1 -StringLength 25 -FolderNameArr @("Dev","Prod") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment