Here’s a quick script to list all of the folders on a share or on a server. This script will use PowerShell to export a list of folders to a CSV file. We’ll be using the Get-ChildItem cmdlet to accomplish this.
Get-ChildItem \\FS01\Shared -Recurse -Name -Directory | Out-File "C:\misc\Folders.csv"
Let’s break this down:
Get-ChildItem is the cmdlet. It is just like “dir” or “ls” where it’s main job is to tell you the contents of a folder. You can learn more about Get-ChildItem here:
Afterwards comes your path, be sure and put it in quotes if there are spaces. Here I used \\FS01\Shared.
-Recurse means we want to continually loop through each subdirectory.
-Directory means we only want directories. You could use -File and get only files, or leave this out to get both
-Name means we just want the name. If you leave this out, you’ll get all of the information of the file or folder, which is a lot of info!
We then pipe the doc to | Out-File where it will export it to the specified path, which comes right after the cmdlet.