{"id":3591,"date":"2021-05-13T11:09:58","date_gmt":"2021-05-13T10:09:58","guid":{"rendered":"https:\/\/www.lieben.nu\/liebensraum\/?p=3591"},"modified":"2021-05-13T11:09:58","modified_gmt":"2021-05-13T10:09:58","slug":"copying-filesystem-permissions-for-long-paths-using-alphafs-nad-powershell","status":"publish","type":"post","link":"https:\/\/lieben.nu\/liebensraum\/2021\/05\/copying-filesystem-permissions-for-long-paths-using-alphafs-nad-powershell\/","title":{"rendered":"Copying filesystem permissions for long paths using AlphaFS nad Powershell"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><a rel=\"noreferrer noopener\" href=\"https:\/\/alphafs.alphaleonis.com\/\" target=\"_blank\">AlphaFS<\/a> is my go-to library when working with Long Paths, since PowerShell&#8217;s built in functions do not support long paths and error out.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As I couldn&#8217;t find good PowerShell examples using GetAccessControl and SetAccessControl with the AlphaFS library, I wanted to post my script here for those googling an example \ud83d\ude42<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\nParam(\n    &#x5B;String]$sourcePath,\n    &#x5B;String]$targetPath\n)\n\n&#x5B;System.Reflection.Assembly]::UnsafeLoadFrom('https:\/\/gitlab.com\/Lieben\/assortedFunctions\/-\/raw\/master\/lib\/AlphaFS.dll?inline=false')\n\n$sourcePath = &#x5B;Alphaleonis.Win32.Filesystem.Path]::GetLongPath($sourcePath)\n$targetPath = &#x5B;Alphaleonis.Win32.Filesystem.Path]::GetLongPath($targetPath)\n\nif(&#x5B;Alphaleonis.Win32.Filesystem.Directory]::Exists($sourcePath)){\n    Write-Verbose \"Detected sourcePath as FOLDER\"\n    $sourceObject = New-Object Alphaleonis.Win32.Filesystem.DirectoryInfo($sourcePath)\n}elseif(&#x5B;Alphaleonis.Win32.Filesystem.File]::Exists($sourcePath)){\n    Write-Verbose \"Detected sourcePath as FILE\"\n    $sourceObject = New-Object Alphaleonis.Win32.Filesystem.FileInfo($sourcePath)\n}else{\n    Throw \"sourcePath not found\"\n}\n\nif(&#x5B;Alphaleonis.Win32.Filesystem.Directory]::Exists($targetPath)){\n    Write-Verbose \"Detected targetPath as FOLDER\"   \n    $targetObject = New-Object Alphaleonis.Win32.Filesystem.DirectoryInfo($targetPath)\n}elseif(&#x5B;Alphaleonis.Win32.Filesystem.File]::Exists($targetPath)){\n    Write-Verbose \"Detected targetPath as FILE\"\n    $targetObject = New-Object Alphaleonis.Win32.Filesystem.FileInfo($targetPath)\n}else{\n    Throw \"targetPath not found\"\n}\n\n$sourceACL = $sourceObject.GetAccessControl(\"Access\")\n$targetObject.SetAccessControl($sourceACL)\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Git: <a href=\"https:\/\/gitlab.com\/Lieben\/assortedFunctions\/-\/blob\/master\/copy-longPathACL.ps1\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/gitlab.com\/Lieben\/assortedFunctions\/-\/blob\/master\/copy-longPathACL.ps1<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>AlphaFS is my go-to library when working with Long Paths, since PowerShell&#8217;s built in functions do not support long paths and error out. As I couldn&#8217;t find good PowerShell examples using GetAccessControl and SetAccessControl with the AlphaFS library, I wanted to post my script here for those googling an example \ud83d\ude42 Git: https:\/\/gitlab.com\/Lieben\/assortedFunctions\/-\/blob\/master\/copy-longPathACL.ps1<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[39,1],"tags":[],"class_list":["post-3591","post","type-post","status-publish","format-standard","hentry","category-powershell","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/3591","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/comments?post=3591"}],"version-history":[{"count":0,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/3591\/revisions"}],"wp:attachment":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/media?parent=3591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/categories?post=3591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/tags?post=3591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}