Solved

Set Owner recursively

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Synchronize a new Active Directory domain with an existing Office 365 tenant
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

759 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now