Click here to Skip to main content
15,891,529 members
Articles / Security
Tip/Trick

Reset file ownership based off parent folder name

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
12 Jun 2011CPOL 13.9K   2  
Reset file ownership based off parent folder name
For anyone who does quota management, I'm sure you've run into issues where the Administrator account is incorrectly the owner of 1,000,000 files located in various users' folders. Of course, you can go to each user's folder and manually reset it to the correct owner. But, why?

If your user folders are set up in this format:
D:\Users\<username>


You can simply use FOR loop along with the ICACLS command to reset the ownership of all of the files (among other things).

Here's the snippet:

SQL
@echo off
SET D= D:\users

FOR /F %%A IN ('DIR %D% /AD /B') DO icacls %D%\%%A /setowner %%A /t /c /q


Just put it in a .bat file and you're good to go!

For more information, check out the documentation on ICACLS at
http://technet.microsoft.com/en-us/library/cc753525(WS.10).aspx.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Systems Engineer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --