How to Copy NTFS Permssion to another Folder???

Author Message
FarisNT

  • Total Posts : 11
  • Scores: 0
  • Reward points : 0
  • Joined: 8/22/2006
  • Status: offline
How to Copy NTFS Permssion to another Folder??? Friday, May 23, 2008 11:37 PM (permalink)
0
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
gci -path c:\123 -Recurse |foreach {get-acl} |Export-csv -path c:\123.csv
and then run the command
import-csv -path c:\123 |set-acl -path d:\123


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 on Friday, May 23, 2008 11:40 PM>
 
#1
    SAPIENScripter

    • Total Posts : 283
    • Scores: 2
    • Reward points : 0
    • Joined: 11/1/2006
    • Location: SAPIEN Technologies
    • Status: offline
    RE: How to Copy NTFS Permssion to another Folder??? Sunday, June 01, 2008 3:22 PM (permalink)
    0
    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
     
    #2
      FarisNT

      • Total Posts : 11
      • Scores: 0
      • Reward points : 0
      • Joined: 8/22/2006
      • Status: offline
      RE: How to Copy NTFS Permssion to another Folder??? Sunday, June 01, 2008 9:32 PM (permalink)
      0
      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
       
      ???????????????????
       
      #3
        SAPIENScripter

        • Total Posts : 283
        • Scores: 2
        • Reward points : 0
        • Joined: 11/1/2006
        • Location: SAPIEN Technologies
        • Status: offline
        RE: How to Copy NTFS Permssion to another Folder??? Monday, June 02, 2008 2:20 AM (permalink)
        0
        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
         
        #4
          SAPIENScripter

          • Total Posts : 283
          • Scores: 2
          • Reward points : 0
          • Joined: 11/1/2006
          • Location: SAPIEN Technologies
          • Status: offline
          RE: How to Copy NTFS Permssion to another Folder??? Monday, June 02, 2008 3:09 AM (permalink)
          0
          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
           
          #5
            SAPIENScripter

            • Total Posts : 283
            • Scores: 2
            • Reward points : 0
            • Joined: 11/1/2006
            • Location: SAPIEN Technologies
            • Status: offline
            RE: How to Copy NTFS Permssion to another Folder??? Monday, June 02, 2008 12:49 PM (permalink)
            0
            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
             
            #6
              FarisNT

              • Total Posts : 11
              • Scores: 0
              • Reward points : 0
              • Joined: 8/22/2006
              • Status: offline
              RE: How to Copy NTFS Permssion to another Folder??? Wednesday, June 04, 2008 11:09 PM (permalink)
              0
              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 on Wednesday, June 04, 2008 11:14 PM>
               
              #7
                SAPIENScripter

                • Total Posts : 283
                • Scores: 2
                • Reward points : 0
                • Joined: 11/1/2006
                • Location: SAPIEN Technologies
                • Status: offline
                RE: How to Copy NTFS Permssion to another Folder??? Thursday, June 05, 2008 2:25 AM (permalink)
                0
                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
                 
                #8

                  Online Bookmarks Sharing: Share/Bookmark

                  Jump to:

                  Current active users

                  There are 0 members and 1 guests.

                  Icon Legend and Permission

                  • 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
                  • Read Message
                  • Post New Thread
                  • Reply to message
                  • Post New Poll
                  • Submit Vote
                  • Post reward post
                  • Delete my own posts
                  • Delete my own threads
                  • Rate post

                  2000-2012 ASPPlayground.NET Forum Version 3.9