{"id":4051,"date":"2009-05-10T21:05:00","date_gmt":"2009-05-10T21:05:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2009\/05\/10\/copy-acl\/"},"modified":"2019-02-18T13:12:39","modified_gmt":"2019-02-18T20:12:39","slug":"copy-acl","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/copy-acl\/","title":{"rendered":"Copy-Acl"},"content":{"rendered":"<p>Today my wife told me about a problem on the family PC.&#160; There were a bunch of PDF files in a directory that had the wrong permissions so my son couldn\u2019t access them.&#160; She modified the ACL on one of them using Explorer and verified that that was the fix.&#160; (This is from a test I ran)<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/BlogFileStorage\/blogs_msdn\/powershell\/WindowsLiveWriter\/CopyAcl_FE79\/image_2.png\"><img decoding=\"async\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/BlogFileStorage\/blogs_msdn\/powershell\/WindowsLiveWriter\/CopyAcl_FE79\/image_thumb.png\" width=\"353\" height=\"483\" \/><\/a> <\/p>\n<p>She then selected them all and tried to do it all at once but when she brought up the Properties, it didn\u2019t have the Security Page anymore:<\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/BlogFileStorage\/blogs_msdn\/powershell\/WindowsLiveWriter\/CopyAcl_FE79\/image_4.png\"><img decoding=\"async\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/BlogFileStorage\/blogs_msdn\/powershell\/WindowsLiveWriter\/CopyAcl_FE79\/image_thumb_1.png\" width=\"346\" height=\"471\" \/><\/a> <\/p>\n<p>She wanted to know if there was some trick to set the ACLs all at once.&#160; I told her that PowerShell could do that.&#160; I showed her how to use Get-Acl and Set-Acl and she gave me a look like, \u201cyou expect me to remember that?\u201d and asked, \u201cwhy don\u2019t you just have a COPY-ACL\u2019 cmdlet.&#160; I told her her how \u201cto ship is to choose\u201d but she wasn\u2019t having any of it.&#160; She clearly thought I was an idiot for not having shipped Copy-Acl.&#160; You know what \u2013 I totally get it.&#160; As a user \u2013 who cares how tough it is to ship software at Microsoft?&#160; All that matters is that you have a need and we either meet it or we don\u2019t.&#160; Sadly that doesn\u2019t change the reality of what it takes to ship things at Microsoft but it does provide some energy to write\/share scripts.<\/p>\n<p>As such, I spent a few minutes and wrote Copy-Acl.&#160; I hope you enjoy it.&#160; I\u2019ve also attached it as a file to this blog.&#160; <\/p>\n<p>Enjoy!<\/p>\n<p>Jeffrey Snover [MSFT]   <br \/>Distinguished Engineer    <br \/>Visit the Windows PowerShell Team blog at:&#160;&#160;&#160; <a href=\"http:\/\/blogs.msdn.com\/PowerShell\">http:\/\/blogs.msdn.com\/PowerShell<\/a>    <br \/>Visit the Windows PowerShell ScriptCenter at:&#160; <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\">http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx<\/a><\/p>\n<p>&#160;<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p>&#160;<\/p>\n<p><font color=\"#004080\" size=\"2\" face=\"Courier New\">&lt;#     <br \/>.SYNOPSIS       <br \/>Copy the ACL from one file to other files <\/font><\/p>\n<p><font color=\"#004080\" size=\"2\" face=\"Courier New\">.DESCRIPTION     <br \/>Takes a file and copies its ACL to one or more other files. <\/font><\/p>\n<p><font color=\"#004080\" size=\"2\" face=\"Courier New\">.PARAMETER FromPath     <br \/>Path of the File to get the ACL from. <\/font><\/p>\n<p><font color=\"#004080\" size=\"2\" face=\"Courier New\">.PARAMETER Destination     <br \/>Path to one or more files to copy the ACL to. <\/font><\/p>\n<p><font color=\"#004080\" size=\"2\" face=\"Courier New\">.PARAMETER Passthru     <br \/>Returns an object representing the security descriptor.&#160; By default, this cmdlet does not generate any output. <\/font><\/p>\n<p><font color=\"#004080\" size=\"2\" face=\"Courier New\">.INPUTS     <br \/>You can Pipeline any object with a Property named &quot;PSPath&quot;, &quot;FullName&quot; or &quot;Destination&quot;. <\/font><\/p>\n<p><font color=\"#004080\" size=\"2\" face=\"Courier New\">.EXAMPLE     <br \/>PS&gt; Copy-Acl Referencefile.txt (dir c:\\temp\\*xml) <\/font><\/p>\n<p><font color=\"#004080\" size=\"2\" face=\"Courier New\">.EXAMPLE     <br \/>PS&gt; dir c:\\files *.xml -recurse | Copy-Acl ReferenceFile.txt <\/font><\/p>\n<p><font color=\"#004080\" size=\"2\" face=\"Courier New\">.LINK     <br \/>Get-Acl      <br \/>Set-Acl <\/font><\/p>\n<p><font color=\"#004080\" size=\"2\" face=\"Courier New\">.NOTES     <br \/>Author:&#160; Jeffrey Snover <\/font><\/p>\n<p><font color=\"#004080\" size=\"2\" face=\"Courier New\">#&gt;     <br \/>#requires -Version 2.0      <br \/>[CmdletBinding(SupportsShouldProcess=$true)]      <br \/>param(      <br \/>[Parameter(position=0,Mandatory=$true)]      <br \/>[String]$FromPath, <\/font><\/p>\n<p><font color=\"#004080\" size=\"2\" face=\"Courier New\">[Parameter(Position=1,Mandatory=$true,ValueFromPipelineByPropertyName=$true)]     <br \/>[Alias(&quot;PSpath&quot;,&quot;fullname&quot;)]      <br \/>[String[]]$Destination, <\/font><\/p>\n<p><font color=\"#004080\" size=\"2\" face=\"Courier New\">[Parameter(Mandatory=$false)]     <br \/>[Switch]$PassThru      <br \/>)      <br \/>Begin      <br \/>{      <br \/>&#160;&#160;&#160; if (! (Test-Path $FromPath))      <br \/>&#160;&#160;&#160; {      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; $ErrorRecord = New-Object System.Management.Automation.ErrorRecord&#160; (      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (New-Object Exception &quot;FromPath ($fromPath) does not point to an existing object&quot;),      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &quot;Copy-Acl.TestPath&quot;,      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &quot;ObjectNotFound&quot;,      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $FromPath      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ) <\/font><\/p>\n<p><font color=\"#004080\" size=\"2\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160; $PSCmdlet.ThrowTerminatingError($ErrorRecord)     <br \/>&#160;&#160;&#160; }      <br \/>&#160;&#160;&#160; $acl = Get-Acl $FromPath      <br \/>}      <br \/>Process      <br \/>{      <br \/>&#160;&#160;&#160; foreach ($Dest in @($Destination))      <br \/>&#160;&#160;&#160; {      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if ($pscmdlet.ShouldProcess($Dest))      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Set-Acl -Path $Dest -AclObject $acl -Passthru:$PassThru      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }      <br \/>&#160;&#160;&#160; }      <br \/>}<\/font><\/p>\n<p><font color=\"#004080\" size=\"2\" face=\"Courier New\"><\/font><\/p>\n<p><a href=\"https:\/\/msdnshared.blob.core.windows.net\/media\/MSDNBlogsFS\/prod.evol.blogs.msdn.com\/CommunityServer.Components.PostAttachments\/00\/09\/60\/12\/05\/Copy-Acl.ps1\">Copy-Acl.ps1<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today my wife told me about a problem on the family PC.&#160; There were a bunch of PDF files in a directory that had the wrong permissions so my son couldn\u2019t access them.&#160; She modified the ACL on one of them using Explorer and verified that that was the fix.&#160; (This is from a test [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4051","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>Today my wife told me about a problem on the family PC.&#160; There were a bunch of PDF files in a directory that had the wrong permissions so my son couldn\u2019t access them.&#160; She modified the ACL on one of them using Explorer and verified that that was the fix.&#160; (This is from a test [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/4051","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=4051"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/4051\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=4051"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=4051"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=4051"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}