(re)Setting rights on user home folders [batch script]

After some troubles with copied user home folders during a migration, the rights were set incorrectly.

As this was about more than just a handful of users, re-setting the rights manually wasn’t a good idea.

After digging around on the net, I adjusted a script so that this could be done automagically.

@echo off
set fold="*"
set fold=%fold:"=%
for /F "tokens=*" %%i in ('dir "%1" /b /ad') do call :UPERM "%%i"
goto end:
 set user=%1
 set user=%user:"=%
 echo %user%
 icacls %user% /grant "%user%":(OI)(CI)(M,RX,R,W,D)

The approach on this is that the user home folder is the same as the username.
The list of directories is taken from the working directory. The subfolders that are put into a variable are the user home folders.
The script then walks through them all and sets (OI)(CI)(M,RX,R,W,D) rights using icacls, so that the users are able to get to their files again.

Look up the icacls help on setting the rights, if you want to adjust the script.

Have fun, hope this helps you.

found onĀ https://arstechnica.com/civis/viewtopic.php?f=17&t=823972

This entry was posted in .bat, Active Directory, batch, command line, File sharing. Bookmark the permalink.