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.