Solved

Script to add AD account to owner of Multiple folders and sub folders

Posted on 2013-06-06
7
685 Views
Last Modified: 2013-07-25
Good Afternoon

I am looking for some advice

I am going through a massive file share but some data i cannot see as users have taken ownership and removed access.

I have noticed that if i take ownership of the folder/file one at a time, then i can add myself backin and not blow away all the other security permissions.

Can this be automated in a batch file/script so that the script goes through each folder and then adds a certain AD account as the owner with full control.  I cannot use the "Replace owner on subcontainers and objects" as i do not want to destroy permissions from sub folders.

I hope this makes sense.

Please let me know if more info is needed.

Mark
0
Comment
Question by:Mark_Mckie
7 Comments
 
LVL 22

Expert Comment

by:yo_bee
ID: 39228878
You can try takeown commands to accomplish this task.
This is a built in command of Windows.

http://technet.microsoft.com/en-us/library/cc753024(v=ws.10).aspx

Run CMD as an Administrator of the Domain or System.

TAKEOWN /F directory /R /A
0
 
LVL 38

Assisted Solution

by:Jim P.
Jim P. earned 250 total points
ID: 39230763
Have you heard of CACLS (Command line Access Control List)?

I'm not great at it but have used a few times to change permissions on files.

Here's the tutorial I use: http://ss64.com/nt/cacls.html
0
 
LVL 54

Expert Comment

by:McKnife
ID: 39233575
Hi.

> I cannot use the "Replace owner on subcontainers and objects" as I do not want to destroy permissions from sub folders.
Why not? It does NOT replace permissions, it replaces the owner. Do it.
[Another tool in addition to takeown is subinacl.exe, it can write other owners as yourself]
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:Mark_Mckie
ID: 39234192
Hi McKnife thanks for that, i am using subinacl to add myself as an owner to all directorys and sub directorys and files using the below command

subinacl /subdirectories "\\ari-ds-01\Public\Corporate Services\*.*" /setowner=NFDG\server

do you know what command i would use to then grant the NFDG\server account full control to all all directorys and sub directorys and files whilst keeping current permissions intact?

Thanks so much.
Mark
0
 
LVL 54

Accepted Solution

by:
McKnife earned 250 total points
ID: 39234262
You can use icacls.exe /grant for that.
0
 

Author Closing Comment

by:Mark_Mckie
ID: 39354292
Just what I needed
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Resolve DNS query failed errors for Exchange
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question