We have system that hosts a folder where every employee has a sub-folder for their private use that is named the same as their username for that system. There have been a couple of times when those rights "per user" get removed. The folders are fine, the admin access is fine. But the user who stores files in that folder loses all rights to it for both read and write. I believe this might be tied to a special archive program that runs every 3 months but i have to track it down.
It wondered if there was a way to walk the directory and read the name of each sub-folder within and Add read/write share permissions for each folder to the user with the same name as the folder.
The main folder named "employees" has sub-folders named johnsmith, fredwilson, maryjones, etc. for about 40 - 50 users
The last two times it happened, i went through the list one by one and restored the read/write permissions. Since the folder names are the exact same as the user names (no spaces) I was hoping there would be a way to walk through the sub-folders under "Employees" and add read/write permissions for each folder to the user with the same name as the folder. The User named "johnsmith" would get read/write only to his sub-folder named "johnsmith". Same for "fredwilson" and "maryjones"
Below is an example layout.
C:\Employees\
fredwilson
johnsmith
maryjones
There are no loose files in the Employees folder and no folders that do not belong to Users that have an account on that system. I just wondered is there was a way to handle the issue programmatically when it occurs > Read in the name of the folder and add read/write permissions for that folder to the user with that name.
Would prefer Powershell or batch but whatever works
I am sure it will be some variation of the "icacls" command.
icacls C:\employees\%user% /grant %user%:(F)
But I am not sure if this is even close as i seldom if ever use icacls
It wondered if there was a way to walk the directory and read the name of each sub-folder within and Add read/write share permissions for each folder to the user with the same name as the folder.
The main folder named "employees" has sub-folders named johnsmith, fredwilson, maryjones, etc. for about 40 - 50 users
The last two times it happened, i went through the list one by one and restored the read/write permissions. Since the folder names are the exact same as the user names (no spaces) I was hoping there would be a way to walk through the sub-folders under "Employees" and add read/write permissions for each folder to the user with the same name as the folder. The User named "johnsmith" would get read/write only to his sub-folder named "johnsmith". Same for "fredwilson" and "maryjones"
Below is an example layout.
C:\Employees\
fredwilson
johnsmith
maryjones
There are no loose files in the Employees folder and no folders that do not belong to Users that have an account on that system. I just wondered is there was a way to handle the issue programmatically when it occurs > Read in the name of the folder and add read/write permissions for that folder to the user with that name.
Would prefer Powershell or batch but whatever works
I am sure it will be some variation of the "icacls" command.icacls C:\employees\%user% /grant %user%:(F)
But I am not sure if this is even close as i seldom if ever use icacls









and I feel sure adding the ability to remove user access from shared folders would fall right in line there somewhere. 
