Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


How to Copy NTFS Permssion to another Folder???

 
Logged in as: Guest
arrSession:exec spGetSession 2,5,60628
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Windows PowerShell >> How to Copy NTFS Permssion to another Folder???
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 How to Copy NTFS Permssion to another Folder??? - 5/23/2008 10:37:29 PM   
  FarisNT

 

Posts: 11
Score: 0
Joined: 8/22/2006
Status: offline
HI
I have a Q regarding to copy NTFS Permssion from a folder to another one
I have a folder that is 200 GB and almost everyfolder have its permssion ..
I need to move this Folder to a new Location on a new server that is a new Domain controler for a new Domain Name
So Using NTBackup will not help even using the normal Copy
I need a way to copy the NTFS Permission from all the folder list to the New Folder on the new server
I try several methods, like export the

       and then run the command

      

But this did not seem to help as and its not working
So I would like to know how can I export the ACL list and import the ACL without having to do the 200 GB of Permission


Thanks

< Message edited by FarisNT -- 5/23/2008 10:40:12 PM >
 
 
Post #: 1
 
 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

(in reply to FarisNT)
 
 
Post #: 2
 
 RE: How to Copy NTFS Permssion to another Folder??? - 6/1/2008 8:32:13 PM   
  FarisNT

 

Posts: 11
Score: 0
Joined: 8/22/2006
Status: offline
hi
thanks for reply
the command get-acl c:\test | set-acl c:\test2 will copy the acl from a single folder to another folder
but in my case .. I need to copy the ACL for a tree of folder and apply it to another Tree of Folder in another Server

???????????????????

(in reply to SAPIENScripter)
 
 
Post #: 3
 
 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

(in reply to FarisNT)
 
 
Post #: 4
 
 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

(in reply to SAPIENScripter)
 
 
Post #: 5
 
 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

(in reply to FarisNT)
 
 
Post #: 6
 
 RE: How to Copy NTFS Permssion to another Folder??? - 6/4/2008 10:09:10 PM   
  FarisNT

 

Posts: 11
Score: 0
Joined: 8/22/2006
Status: offline
HI
Thanks for the Script and also sorry for the Delay in the reply
The script seem to be working fine . even if it did not copy the Root ACL but its not a probem
the only problem I found that when the folder is inherited its ACL from the perant, it will not work
and I would like to ask you what does the PSIscontainer do
The Script work fine . Thanks

I have something i did not understand in power shell
that is the bracket.. when we use the { and when we use the (

< Message edited by FarisNT -- 6/4/2008 10:14:54 PM >

(in reply to SAPIENScripter)
 
 
Post #: 7
 
 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

(in reply to FarisNT)
 
 
Post #: 8
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Windows PowerShell >> How to Copy NTFS Permssion to another Folder??? Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts