SOLVED

Script to change permissions on multiple folders

%3CLINGO-SUB%20id%3D%22lingo-sub-3181035%22%20slang%3D%22en-US%22%3EScript%20to%20change%20permissions%20on%20multiple%20folders%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3181035%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20involved%20in%20a%20project%20to%20migrate%20users%20H%3A%20drive%20data%20to%20OneDrive.%26nbsp%3B%20After%20we%20migrate%20their%20data%20to%20OneDrive%2C%20we%20want%20to%20change%20their%20H%3A%20drive%20folder%20and%20files%20to%20read-only.%26nbsp%3B%20I%20have%20found%20a%20cacls%20command%20to%20change%20the%20permissions%20(CACLS%26nbsp%3BK%3A%5Cfoldername%20%2FT%20%2FE%20%2FC%20%2FP%20username%3AR)%20but%20I%20need%20to%20do%20this%20for%20specific%20user's%20H%3A%20drives.%26nbsp%3B%20o%20I%20need%20the%20script%20to%20read%20from%20a%20txt%20file%20to%20perform%20the%20cacls%20command%20on%20each%20of%20the%20folders%20in%20the%20txt%20file.%26nbsp%3B%20Is%20there%20a%20smart%20person%20out%20there%20that%20can%20help%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3181035%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3183062%22%20slang%3D%22en-US%22%3ERe%3A%20Script%20to%20change%20permissions%20on%20multiple%20folders%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3183062%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1310650%22%20target%3D%22_blank%22%3E%40craigbowens%3C%2FA%3E%26nbsp%3BYou%20could%20try%20something%20like%20using%20c%3A%5Ctemp%5Cusers.txt%20as%20input%20with%20a%20username%20per%20line.%20Not%20tested%20this%2C%20but%20I%20think%20it%20should%20work...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3Eforeach%20(%24user%20in%20get-content%20c%3A%5Ctemp%5Cusers.txt)%20%7B%0Acacls.exe%20%22k%3A%5C%24(%24user)%22%20%2FT%20%2FE%20%2FC%20%2FP%20%22%24(%24user)%3AR%22%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3187176%22%20slang%3D%22en-US%22%3ERe%3A%20Script%20to%20change%20permissions%20on%20multiple%20folders%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3187176%22%20slang%3D%22en-US%22%3EDid%20this%20work%20for%20you%3F%3C%2FLINGO-BODY%3E
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)
Solution

@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