Using PowerShell to rename folders and change ACLs

Here’s something I had to do at work a few weeks back. I wanted to blog about it since then but never got around to it.

We had copied a bunch of folders from one location to another. Since this was a copy the folders lost their original ACLs. I wanted to do two things – 1) the folder names were in the format “LastName, FirstName” and I wanted to change that to “username” (I had a CSV file with mappings so I could use that to do the renaming). 2) I wanted to change the ACLs so the user had modify rights to the folders.

For the first task here’s what I did:

Note that apart from renaming I also move the folder to a different path (coz I had multiple source locations and wanted to combine them all into one).

For the second task here’s what I did:

Later on I realized the folders still had the BUILTIN\Users entity with full control so I had to remove these too. The code for that was slightly different so here goes:

This is a good article on what I was doing above. And this TechNet article is a useful resource on the various rights that can be assigned.