Create test directory tree with PowerShell

I needed to create directory tree structure to test something and I thought that it might be the right time to try out PowerShell.

An hour ago I didn’t know PowerShell, and I still don’t — I’m pretty sure there this is noob script… Nonetheless it does what it meant to and is better than “hello world” for a first script 😉

function New-TestFS ([string]$Path = "c:fstest", [int]$Depth = 1) { 
	if ($Depth -gt 10) { 
		return
	}
	Write-Host "#### NEW DIR: $Path $Depth"
	New-Item -ItemType directory -path $Path -ErrorAction SilentlyContinue 
  	900..999 | % { 
		New-TestFS -Path ("$PathDir$_") ($Depth + 1)
	} 
	Write-Host "#### NEW FILES: $Path $Depth"
	for ( $i=1; $i -le (Get-Random -Minimum 100 -Maximum 199); $i++ ) { 
		Write-Host "FILE: $PathFile$i.txt"
		fsutil file createnew ("$PathFile$i.txt") 0
	} 
	
}

Kudos to Jeff Wouters for his powershell example 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s