Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Set Owner recursively

Posted on 2013-02-01
2
2,315 Views
Last Modified: 2013-02-01
I have been reading the Scripting Guy's post on setting file ownership for a specific user.

His code is:

$objUser = New-Object System.Security.Principal.NTAccount("fabrikam", "kenmyer")
$objFile = Get-Acl C:\Scripts\Test.txt
$objFile.SetOwner($objUser)
Set-Acl -aclobject $objFile -path C:\Scripts\Test.txt

Open in new window


This works great for a specific folder. I am trying to get it to work recursively so that all subfolders and files have the same specified owner.

How can this be done?
0
Comment
Question by:Joseph Moody
2 Comments
 
LVL 16

Accepted Solution

by:
Rajitha Chimmani earned 500 total points
ID: 38844293
Try using the code given in link below

$acct1 = New-Object System.Security.Principal.NTAccount("fabrikam", "kenmyer")
$profilefolder = Get-Item MyFolder
$acl1 = $profilefolder.GetAccessControl()
$acl1.SetOwner($acct1)
dir -r c:\Users\goyuix\temp | set-acl -aclobject $acl1

Ref: http://serverfault.com/questions/375911/change-owner-recursively-with-powershell

Alternate option given in link below

http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/879783fc-37c5-4126-b0a7-378d90a28478/
0
 
LVL 22

Author Closing Comment

by:Joseph Moody
ID: 38844452
You are awesome!! Thank you.
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

860 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