Login | |
|
 |
RE: How to Copy NTFS Permssion to another Folder??? - 6/1/2008 2:22:39 PM
|
|
 |
|
| |
SAPIENScripter
Posts: 275
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
|
Really, the best approach for this is to use SUBINACL. I think it has a parameter to copy an ACL. In Powershell, an expression like this should copy the ACLfrom one folder to another: PS C:\> get-acl c:\test | set-acl c:\test2 I hope it goes without saying to test and retest in a non-production environment.
_____________________________
Jeffery Hicks Windows PowerShell MVP SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com Follow Me: http://www.twitter.com/JeffHicks
|
|
| |
|
|
|
 |
RE: How to Copy NTFS Permssion to another Folder??? - 6/2/2008 1:20:54 AM
|
|
 |
|
| |
SAPIENScripter
Posts: 275
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
|
You'll have to recurse through the directory trees. I'm not saying this will be quick and easy. This will get the acl's for the source directory tree: dir c:\test -recurse | where {$_.PSIsContainer} | get-acl I think this is going to take a script. You'll need to save the original path and ACL to a variable, then enumerate the variable and apply the acl to the target tree, substituting the top level name. I bet you could use a hash table to store the source paths and acls. $source=@() dir c:\test -recurse | where {$_.PSIsContainer} | foreach { $source+=@{$_.Fullname=(Get-Acl $_.Fullname)} } I don't have time to complete the solution but I hope this gets you started. You should be able to enumerate the hash table and use the name of each key for the target path, substituting parent names as necessary.
_____________________________
Jeffery Hicks Windows PowerShell MVP SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com Follow Me: http://www.twitter.com/JeffHicks
|
|
| |
|
|
|
 |
RE: How to Copy NTFS Permssion to another Folder??? - 6/2/2008 2:09:54 AM
|
|
 |
|
| |
SAPIENScripter
Posts: 275
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
|
I was in a hurry and goofed. This is the better way to create the hash table. $source=@{} dir c:\test -recurse | where {$_.PSIsContainer} | foreach { $source.Add($_.Fullname,(Get-Acl $_.Fullname)) } It looks like the ACL gets stored but I'm not having any luck enumerating it and I have to go teach a class right now. I hope this is enough to keep you going.
_____________________________
Jeffery Hicks Windows PowerShell MVP SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com Follow Me: http://www.twitter.com/JeffHicks
|
|
| |
|
|
|
 |
RE: How to Copy NTFS Permssion to another Folder??? - 6/2/2008 11:49:57 AM
|
|
 |
|
| |
SAPIENScripter
Posts: 275
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
|
Alright, I finally got my head in the game. I think you can use an expression like this if I understand your situation. dir c:\test -recurse | where {$_.PSIsContainer} | foreach { $target= ($_.fullname).replace("C:\test","D:\test2") Get-Acl $_.Fullname | Set-Acl $target -whatif } C:\Test is the directory tree that was backed up. D:\Test2 is the root of restored tree. A recursive listing of each subfolders should be identical. The $target simply takes the current full filename path like c:\test\foo\bar\ and swaps out the root so it becomes D:\test2\foo\bar. The Get-Acl | Set-Acl is pretty much what I showed you before. Make sense?
_____________________________
Jeffery Hicks Windows PowerShell MVP SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com Follow Me: http://www.twitter.com/JeffHicks
|
|
| |
|
|
|
 |
RE: How to Copy NTFS Permssion to another Folder??? - 6/5/2008 1:25:52 AM
|
|
 |
|
| |
SAPIENScripter
Posts: 275
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
|
PSContainer is a property (remember that everything in PowerShell is an object) that indicates the object is a container, ie directory. The { } are used to indicate a script block. Within the braces are PowerShell expressions that are executed, typically be a cmdlet. For example, the Where-Object cmdlet takes a script block as a parameter. The PowerShell expression within the script block is executed, in this situation it needs to return TRUE or FALSE, and the cmdlet uses that information to decide how to behave. The ( ) is used by the shell itself, generally, and instructs PowerShell to evaluate or run the code within the parentheses and substitute the result into the original PowerShell expression.
_____________________________
Jeffery Hicks Windows PowerShell MVP SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com Follow Me: http://www.twitter.com/JeffHicks
|
|
| |
|
|
|
| |
|
|
 |
|
 |
|
|