Solved

Set Owner recursively

Posted on 2013-02-01
2
2,290 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 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