Script to change permissions on multiple folders

New Contributor

I am involved in a project to migrate users H: drive data to OneDrive.  After we migrate their data to OneDrive, we want to change their H: drive folder and files to read-only.  I have found a cacls command to change the permissions (CACLS K:\foldername /T /E /C /P username:R) but I need to do this for specific user's H: drives.  o I need the script to read from a txt file to perform the cacls command on each of the folders in the txt file.  Is there a smart person out there that can help?

4 Replies
best response confirmed by craigbowens (New Contributor)

@craigbowens You could try something like using c:\temp\users.txt as input with a username per line. Not tested this, but I think it should work...


foreach ($user in get-content c:\temp\users.txt) {
cacls.exe "k:\$($user)" /T /E /C /P "$($user):R"


Did this work for you?

Yes!  Thank you very much!

Nice, please mark my answer as solution to mark it as solved