Generate a folderstructure with the help of powershell from template with NTFS permissions

The estimated reading time 2 minutes

Generate a folderstructure with the help of powershell from template with NTFS permissions

some customer asked me to help them creating a special folderstructure with ntfs permission in some subfolders. In my case we want to break inheritance beginning this subfolder.

folderstructure-powershell01

Have a look at this simple structure

We want to generate a new project inside “folder02” so there should be a folder like project002 containing subfolders “01,02,03” (these subfolders should not have the same permissions from parent folder ) A special user with permissions should generate this as simple as possible.

So this is the challenge. ( Yes I know you should not break inheritance inside a folderstructure so this is not best practices)

So I wrote a little powershell script which asks the name of the folder in a textbox and let the user choose the folder where to generate the new project.

NOTE: you need of course a special user with the appropriated permissions who should execute this script

Enough said so here is my script on github

So have a look on my permission inside this structure

folderstructure-powershell02

the first step is to change the variables as mentioned in the comments in top of the script (sourcepath in my case is the top folder of the template here C:\files\projecttemplate)

folderstructure-powershell03

When you start the script it will ask for the name of the folder you want to create

folderstructure-powershell04

After this it wants to know where to generate the folder and integrate the templates

folderstructure-powershell05

If the script has finished there should be a folder “project002” containing folders with the same permission as template folders

folderstructure-powershell06

See the overview of the new folders

folderstructure-powershell07

The action should also be logged

folderstructure-powershell08

After testing the script I generated a exe file with my brand new ISEsteroids (http://www.powertheshell.com/isesteroids/) so users can handle it as a normal program.

Give me some feedback concering this script.

Write a comment.

Thank you

Print Friendly, PDF & Email
Was this article helpful?
YesNo
0 0 votes
Article Rating
Subscribe
Notify of
guest
8 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
sanniso
sanniso
3 years ago

Hi!

is this script working recursively when having a bunch of sub folders?

Thanks,
sanni

K.J.
K.J.
3 years ago

Hi A.K.,

Thanks for the script, I wonder if it’s possible via powershell, to add a step in the script, which allows the user to choose a subset of the folders in the template eg via a checkbox – folder treeview. I’ve found a solution via Python, but would prefer to use powershell.

Thanks,
K

K.J.
K.J.
Reply to  A.K.
3 years ago

Hi Alexander,
Thanks, but from what I could find: the basic FolderBrowserDialog does not support a multiselect action.
For my purpose, I would need to have the user make a (multi)-selection of the folders that are in the template folder structure.
Best,
Koen

Michael
Michael
6 years ago

I need a Windows 10 powershell script that can MOVE multiple files that are inside multiple folders (in which each file has an extension of “.wmv”), to another single external drive. All these .”wmv” files can keep their existing permissions in their new location, although they can carry temp permissions if this makes it easier.
Is it possible to build such a script possible?
Thnaks so much for your awesome knowledge.