• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 385
  • Last Modified:

Script to change permissions

My organisation uses re-directed folders for Favorites and Desktop

The structure is as follows...

D:\Users\%USERNAME%\Desktop
D:\Users\%USERNAME%\Favorites

I'd like a script that will change the ownership and add full permission across every subfolder under the Users folder to the name of the root folder.

For example...

D:\USERS\jbloggs

All sub folders within the jbloggs folder will have ownership changed to jbloggs and full permission granted to jbloggs. (These permissions must be added, and not replaced. The Domain Administrators group still needs full permission across all subfolders)
0
antonioking
Asked:
antonioking
  • 3
  • 2
1 Solution
 
GovvyCommented:
Use command line:

>cacls /G
0
 
Steve KnightIT ConsultancyCommented:
Can use a for loop:

@echo off
for /d %%A in (D:\users) do (
  echo cacls %%A /e /t /g domain\%%~nA:C
  echo na_ntfschown /R domain\%%nA %%A
)

That will give you modify permissions for each folder for the person with that name under domain.

Remove the word echo once happy with what it shows to let it actually do it!

na_ntfschown should do it for taking ownership as the next line

Please test one line of each first!

Steve
0
 
antoniokingAuthor Commented:
This doesn't seem to be picking up the sub folder names?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Steve KnightIT ConsultancyCommented:
It should pick up top level folders in D:\users and then set permissions and ownership on that level to flow down into subdirs and folders.  Are you getting something different?  You should have a link somewhere around here for "related question".  Might be worth clicking on that and posting an update if needed as otherwise other experts won't see this Q now it shows as closed

Steve
0
 
antoniokingAuthor Commented:
Here's an update that worked for me...

@echo off
CD /d D:\Users
for /d %%A in (*) do (
  echo cacls %%A /e /t /g domain\%%~nA:C
  echo na_ntfschown /R domain\%%~nA %%A
)
0
 
Steve KnightIT ConsultancyCommented:
Yes good point there.  "~" missed of the second domain username, so it may have passed domain\d:\users\username, and the path should have been d:\users\*, or move into the dir and then use * like you have.

Must have been too early for me at 4:30pm, normally best at answering on here about midnight!

Steve
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now