Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to use Powershell to change owner of a folder, recursively.

I'm basically using this code:

$acct1 = New-Object System.Security.Principal.NTAccount('DOMAIN\Enterprise Admins')
$profilefolder = Get-Item MyFolder
$acl1 = $profilefolder.GetAccessControl()
set-acl -aclobject $acl1 -path MyFolder

This will change ownership at the first level, but not for any subfolders or files. Is there a way to extend the scope to all content of MyFolder?

share|improve this question

The takeown command does exactly what you're trying to do. It's a regular windows utility.

This snippet will apply ownership to the current user, but you can set it to any user you want.

takeown /f "c:\folder\subfolder" /r

If you run into trouble make sure you are running the cmd/powershell window with administrator permissions. Same applies to the other powershell specific answer.

share|improve this answer

The Set-ACL cmdlet will take the path parameter from the pipe, so the recommended way is to pipe the contents of a directory to set the owner on each item:

dir -r c:\Users\goyuix\temp | set-acl -aclobject $acl1

That will recursively set the owner on all the folders/files in the temp directory in my profile.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.