views:

29

answers:

1

I'm trying to do an xcopy /o equivalent to copy a template folder with subdirectories which contain their own appropriate acl to create a new target directory with the same subdirectories and their respective acl in a windows 2008 server environment.

for example..

the template directory would be  templatedir
- sql 
- pm 
- dev 

targetdir  
- sql 
- pm 
- dev

with each subdir having the same acl

here is what i have come up with so far

PS C:\> dir c:\templatefolder -recurse | where {$_.PSIsContainer} | foreach { 
$target= ($_.fullname).replace("C:\templatefolder","D:\targetfolder") 
  Get-Acl $_.Fullname | Set-Acl $target -whatif 
} 

how do i modify this so it includes the inheritance and copies the templatedir's acl? it currently only does the subfolders. thanks in advance

A: 

dir is an alias for Get-ChildItem so it will return all the "child" items in the template dir but not the dir itself. To copy the ACLs for the template dir add this command e.g.:

PS C:\> Get-Acl C:\templatefolder | Set-Acl -path D:\targetfolder -whatif 

As for setting up inheritance, this would be much easier using icacls.exe:

C:\PS> icacls <name> /inheritance:e

Run icacls /? to see help on this Windows utility.

Keith Hill