ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Controlling Folder Depth when Exporting Folder ACL to Excel via Powershell

    Scheduled Pinned Locked Moved IT Discussion
    powershellactive directoryacl
    2 Posts 2 Posters 1.3k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • wirestyle22W
      wirestyle22
      last edited by

      The below script finds the permissions for the directory, but goes all the way through the entire file structure.

      $FolderPath = dir -Directory -Path "P:\Public" -Recurse -Force
      $Report = @()
      Foreach ($Folder in $FolderPath) {
          $Acl = Get-Acl -Path $Folder.FullName
          foreach ($Access in $acl.Access)
              {
                  $Properties = [ordered]@{'FolderName'=$Folder.FullName;'AD
      Group or
      User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
                  $Report += New-Object -TypeName PSObject -Property $Properties
              }
      }
      $Report | Export-Csv -path "C:\export\permissions.csv"
      

      I need to go only two levels deep. I read that you can use Get-ChildItemToDepth but I am having trouble with the syntax if anyone can help.

      1 Reply Last reply Reply Quote 1
      • ObsolesceO
        Obsolesce
        last edited by Obsolesce

        Try this instead:

        $FolderPath = Get-ChildItem -Recurse -Depth 2 -Path "P:\Public" -Force

        Where -Depth is the how many levels deep you want to go.

        If you want to see what a cmdlet can do, you can use:

        Get-Help Get-ChildItem -Full

        1 Reply Last reply Reply Quote 2
        • 1 / 1
        • First post
          Last post