locked
Powershell Reports RRS feed

  • Question

  • I am currently running a powershell script (seen below) that gives me who has access to what folder in that drive.  Currently the path report shows every folder (ie E:\Shared\Public\Pictures\Logos.) I ready only need to see access to the first two levels (ie E:\Shared\Public\Pictures) and who has permissions (and what perssionions) to those folders.  how I can I alter the script so I can do this ?  NOTE:  I am a powershell newbie.

     $FolderPath = dir -Directory -Path 'E:\Shared' -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:\Temp\Shared_FolderPermissions.csv" 

    Tuesday, May 5, 2020 5:19 PM

Answers

  • Use the -Depth switch.

    $FolderPath = Get-ChildItem -Directory -Path 'E:\Shared' -Recurse -Force -Depth 2

    • Marked as answer by Keith_7 Tuesday, May 5, 2020 10:30 PM
    Tuesday, May 5, 2020 6:03 PM

All replies

  • Use the -Depth switch.

    $FolderPath = Get-ChildItem -Directory -Path 'E:\Shared' -Recurse -Force -Depth 2

    • Marked as answer by Keith_7 Tuesday, May 5, 2020 10:30 PM
    Tuesday, May 5, 2020 6:03 PM
  • would I be correct in saying if I want to go one folder deeper I would type -Depth 3?
    Tuesday, May 5, 2020 9:42 PM
  • Yes.
    Tuesday, May 5, 2020 9:48 PM
  • thanks for everything
    Tuesday, May 5, 2020 10:30 PM