Taking ownership of multiple files with the script

I was wondering if I can get a powershell or vb script to take ownership of multiple files so that I can modify and add NTFS permissions using the script. I get access denied error when even trying to do NTFS inventory.

Below is what I need to do but not just manually for one folder, I need to fix thousands of folders. Thank you very much.


To take ownership of a file or folder, follow these steps:
Press and hold the folder that you want to take ownership of, then tap Properties. (If you are using a mouse, right-click the folder, and then click Properties.)
Tap or click the Security tab, tap or click Advanced, then tap or click Change. If you are prompted for an administrator password or for confirmation, type the password or provide confirmation.
Type the name of the person that you want to give ownership to, and then click Check Names.
Note The account name for the person that you are assigning ownership to is displayed.
Click OK.
If you want this person to be the owner of the files and subfolders that are contained in this folder, select the Replace owner on subcontainers and objects check box.
Click OK.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Will SzymkowskiSenior Solution ArchitectCommented:
I have found the easiest and most effective way to take ownership of entrie directories is using the TAKEOWN command.

You can also do this on remove systems as well. Below is the TechNet on the simply syntax for the TAKEOWN command.

TAKEOWN /S remotecomputer /U domain\administrator /P password /F Share1\* /R /A

Open in new window

The above command will take owner of a share called Share1 on a computer called remotecomputer. /R is recursive and /A (assign to administrator group). If /A is not used then it will grant the account you are using with the ownership permissions.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
creative555Author Commented:
I have just read that there is an issue If  taking ownership actually would break the home drive access for the user.....

 This is due to the ‘Grant user exclusive rights’ policy.

Let me know what you think. What would also be a safe and obviously non-destructive approach.
Is there way to do it through group policy?
Will SzymkowskiSenior Solution ArchitectCommented:
All you need to do is test this theory on a single Share. Create a Test Share and then use the TAKEOWN command and run it against that share only, see what happens. If memory serves, i have not had an issue when i used this command in the past.

creative555Author Commented:
OK. Thank you so much. I will test it first and let you know if this will work :)
creative555Author Commented:
Thank you so much, Will! Excellent answer.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Active Directory

From novice to tech pro — start learning today.