Link to home
Start Free TrialLog in
Avatar of ARampton
ARamptonFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Powershell to copy File Owner from one file to another

I am trying to copy File & Folder Owner details from a duplicate folder structure (restored from a backup) to their original source folder structure after resetting permissions that required me to take ownership of every original

Using Get-ACL gives me the correct original owner
Get-ACL "$SFullPath" | Select-Object Owner
Owner
-----
ARCHITECTS\NCoates

I have tried using it in Set-ACL  but Powershell does not like this
$NewACL = Get-ACL "$SFullPath" | Select-Object Owner
Set-ACL "$TFullPath" $NewACL

I have also tried SetOwner but I think the format of Get-ACL "$SFullPath" | Select-Object Owner includes too much data
$OldOwner = Get-ACL "$SFullPath" | Select-Object Owner
$NewACL.SetOwner([System.Security.Principal.NTAccount] $OldOwner )

How do I correct the format of Get-ACL "$SFullPath" | Select-Object Owner to just show the user name?

Or is there a simpler way of using Powershell to do what I want?
Avatar of Scott C
Scott C
Flag of United States of America image

It's not Powershell, but RoboCopy will do what you want.

http://social.technet.microsoft.com/wiki/contents/articles/1073.robocopy-and-a-few-examples.aspx

I think I may have found what you are looking for.  Take a look at this blog.

http://blogs.msdn.com/b/powershell/archive/2009/05/11/copy-acl.aspx
Avatar of ARampton

ASKER

Sorry but I don't want to use RoboCopy

Copy-ACL does not seem to allow only copying Owner information
Restore the files backing up with directory folder permissions that will bring all permissions back as before.
ASKER CERTIFIED SOLUTION
Avatar of ARampton
ARampton
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial