Wednesday, December 9, 2015

Creating a directory structure tree recursively in PowerShell

I was recently working on converting some command-line scripts over to PowerShell and I discovered a very lengthy script that was using a long series of mkdir commands to create one directory after the other in a directory tree.

Ultimately, the mkdir command was simply trying to make the deepest folder in the directory structure.

However, accomplishing this using PowerShell is extremely easy using the New-Item command!

This command will create the entire directory structure in the folder tree/folder hierarchy for you automatically:

New-Item "C:\Temp\distribution\package\db\Scripts\SQL Server" -ItemType Dir

No comments:

Post a Comment