Change owner recursively with Powershell?

Posted by Mikael Grönfelt on Server Fault See other posts from Server Fault or by Mikael Grönfelt
Published on 2012-04-02T14:03:43Z Indexed on 2012/10/28 17:03 UTC
Read the original article Hit count: 290

Filed under:
|
|
|

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()
$acl1.SetOwner($acct1)
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?

© Server Fault or respective owner

Related posts about powershell

Related posts about ntfs