none
Moving File Structure Skeleton and Copying ACL RRS feed

  • Question

  • I'm working on moving a set of folders from one server location to another. Everything seems to work fine except the last for-each isn't processing. I'm not receiving any error. Files copy okay but the permissions do not. 

    $destination ='\\someserver\legal\test1'

    $source = ''\\someserver\legal\test2'


    Get-ChildItem -Path $source -recurse | Where-Object {$_.PSIScONTAINER -EQ $TRUE} |  
    ForEach-Object { $_.FullName -replace [regex]::Escape($source), $destination } | 
    ForEach-Object { $null = New-Item -ItemType Container -Path $_ }  
    Get-ChildItem -Path $source -recurse | Where-Object {$_.PSIScONTAINER -EQ $TRUE} |
    ForEach-Object {


       Get-Acl -Path $_.FullName | Set-Acl -Path "$destination\$(Split-Path -Path $_.FullName -Leaf)"
       write-host "copying ACL for $_"
    }

    Edit: Found and corrected part of my mistake. With the code above everything is working except for changing the ACL on the child objects. 


    • Edited by Breaker1253 Wednesday, April 2, 2014 5:01 PM
    Wednesday, April 2, 2014 4:44 PM

Answers

  • Solved:

    $destination ='\\someserver\legal\test1'

    $source = ''\\someserver\legal\test2'

    Get-ChildItem -Path $source -recurse | Where-Object {$_.PSIScONTAINER -EQ $TRUE} |  
    ForEach-Object { $_.FullName -replace [regex]::Escape($source), $destination } | 
    ForEach-Object { $null = New-Item -ItemType Container -Path $_ }  
    Get-ChildItem -Path $source -recurse | Where-Object {$_.PSIScONTAINER -EQ $TRUE} |
    ForEach-Object {
    $var = $_.FullName -replace [regex]::Escape($source),$destination

       Get-Acl -Path $_.FullName | Set-Acl -Path "$var\"
       write-host "copying ACL for $_"
    }

    • Marked as answer by Breaker1253 Wednesday, April 2, 2014 5:09 PM
    Wednesday, April 2, 2014 5:09 PM

All replies

  • Solved:

    $destination ='\\someserver\legal\test1'

    $source = ''\\someserver\legal\test2'

    Get-ChildItem -Path $source -recurse | Where-Object {$_.PSIScONTAINER -EQ $TRUE} |  
    ForEach-Object { $_.FullName -replace [regex]::Escape($source), $destination } | 
    ForEach-Object { $null = New-Item -ItemType Container -Path $_ }  
    Get-ChildItem -Path $source -recurse | Where-Object {$_.PSIScONTAINER -EQ $TRUE} |
    ForEach-Object {
    $var = $_.FullName -replace [regex]::Escape($source),$destination

       Get-Acl -Path $_.FullName | Set-Acl -Path "$var\"
       write-host "copying ACL for $_"
    }

    • Marked as answer by Breaker1253 Wednesday, April 2, 2014 5:09 PM
    Wednesday, April 2, 2014 5:09 PM
  • Robocopy would be simpler.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, April 2, 2014 5:22 PM
    Moderator
  • Would robocopy exclude files? 
    Wednesday, April 2, 2014 5:29 PM
  • It isn't hard to find out.

    http://www.google.com/search?&q=robocopy+documentation


    -- Bill Stewart [Bill_Stewart]

    Wednesday, April 2, 2014 5:51 PM
    Moderator