Here’s a fun little script I worked on recently. Essentially, what it does is accept an input of a text file holding one username on each line and create a new folder in a specified path that only that user has rights to for each user in the input file. The use case for this would be if you were trying to move users’ profile folders to new shared drive on the network, or perhaps they didn’t exist and you need to create them from scratch. Have a look – enjoy!
FOR /F %%i IN (users.txt) DO (
if exist “\[PATH]%%i” (
set TEST=changed
echo %%i already exists.
) else (
set TEST=needToChange
)if “%TEST%”==”needToChange” (
echo For %%i >> log.txt
echo Creating %%i
if not exist “\[PATH]%%i” md “\[PATH]%%i” >> log.txt
echo Blocking inheritance…
icacls \[PATH]%%i /inheritance:r /Q >> log.txt
echo Granting permissions for %%i…
icacls \[PATH]%%i /grant:r “%%i:(OI)(CI)F” >> log.txt
icacls \[PATH]%%i /grant:r “Administrators:(OI)(CI)F” >> log.txt
echo Setting Owner to %%i…
icacls \[PATH]%%i /setowner %%i /T /C /Q >> log.txt
echo Removing default Users…
icacls \[PATH]%%i /remove Users /T /C /Q >> log.txt
echo Done! && echo ———
)
)
I’ve also included the script and a sample input file zipped up here for your downloading pleasure.