Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8524733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:46:19+00:00 2026-06-11T07:46:19+00:00

The PowerShell script below will list out all shared folders (excluding hidden shared folders),

  • 0

The PowerShell script below will list out all shared folders (excluding hidden shared folders), then list out all sub-folders and finally get the ACL information of each of them and export to a CSV file.

However, I’m trying to set the limit of the sub-folder it can drill into. For example, if I set it to 3, the script will get the ACL information of first three sub-folders. How can I do this?

Input:

path=\\server\sharefolder0\subfolder01\subfolder02
path=\\server\sharefolder1\subfolder11\subfolder12\subfolder13\subfolder14
path=\\server\sharefolder2

Expected result:

path=\\server\sharefolder0
path=\\server\sharefolder0\subfolder01
path=\\server\sharefolder0\subfolder01\subfolder02
path=\\server\sharefolder1
path=\\server\sharefolder1\subfolder11
path=\\server\sharefolder1\subfolder11\subfolder12
path=\\server\sharefolder2

This is the code:

$getSRVlist = Get-Content .\server.txt
$outputDirPath=".\DirPathList.txt"
$outputACLInfo=".\ACLInfo.CSV"
$header="FolderPath,IdentityReference,Rights"
Del $outputACLInfo
add-content -value $header -path $outputACLInfo
foreach ($readSRVlist in $getSRVlist)
{
   foreach ($readShareInfoList in $getShareInfoList=Get-WmiObject Win32_Share
   -computerName $readSRVlist | Where {$_.name -notlike "*$"} | %{$_.Name})
   {
      foreach ($readDirPathList in
      $getDirPathList=get-childitem \\$readSRVlist\$readShareInfoList -recurse
      | where {$_.PSIsContainer})# | %{$_.fullname})
      {
         $getACLList=get-ACL $readDirPathList.fullname | ForEach-Object
         {$_.Access}
         foreach ($readACLList in $getACLList)
         {
            $a = $readDirPathList.fullname + "," +
            $readACLList.IdentityReference + "," +  $readACLList.FileSystemRights
            add-content -value $a -path $outputACLInfo
         }
      }
   }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:46:20+00:00Added an answer on June 11, 2026 at 7:46 am

    Recursion is your friend. Try this:

    $maxDepth = 3
    
    function TraverseFolders($folder, $remainingDepth) {
      Get-ChildItem $folder | Where-Object { $_.PSIsContainer } | ForEach-Object {
        if ($remainingDepth -gt 1) {
          TraverseFolders $_.FullName ($remainingDepth - 1)
        }
      }
    }
    
    TraverseFolders "C:\BASE\PATH" $maxDepth
    

    Edit: Now I see what you mean. For checking the first three parent folders of a given path try this:

    $server   = "\\server\"
    $path = ($args[0] -replace [regex]::escape($server), "").Split("\\")[0..2]
    for ($i = 0; $i -lt $path.Length; $i++) {
      Get-ACL ($server + [string]::join("\", $path[0..$i])
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the below powershell script I am passing three string parameters. The $ComputerName parameter
I have a PowerShell script: param ( [Parameter(Mandatory=$true)][string]$input, [Parameter(Mandatory=$true)][string]$table ) Write-Host Args: $Args.Length Get-Content
I have a powershell script that will generate an email for users whose password
I've written a Powershell script which will compare two databases and come up with
I'm using the PowerShell script below to set anonymous user identity and authentication methods
i Have an arguments like the one below which i pass to powershell script
I'm trying to write a PowerShell script that will do the following: Executes a
I have the following PowerShell script that will parse some very large file for
I want to write a PowerShell script that will recursively search a directory, but
I have a Powershell script where I would like to create a generic List

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.