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

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?
ARamptonIT ManagerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott CSenior EngineerCommented:
It's not Powershell, but RoboCopy will do what you want.


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

ARamptonIT ManagerAuthor Commented:
Sorry but I don't want to use RoboCopy

Copy-ACL does not seem to allow only copying Owner information
Prashant ShrivastavaConsultantCommented:
Restore the files backing up with directory folder permissions that will bring all permissions back as before.
ARamptonIT ManagerAuthor Commented:
Found a solution using | Format-Wide | Out-String and then .Trim()

I don't understand why getting correct PowerShell output in correct format seems so difficult

$SourceOwner = Get-ACL "$SFullPath" | Select-Object Owner | Format-Wide | Out-String
$SourceOwner = $SourceOwner.Trim()

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.