powershell folder structure command - csv output

pma111
pma111 used Ask the Experts™
on
is there a way via powershell to supply a file share path e.g. \\server\share\directory and it report all sub directories (but only folders), and sub directories within those, out to a csv file? a bit similar to the old windows DIR command, but to not show all files within folders, only folder details

e.g. if I supply \\server\share - I get a report of all folders (as deep into the structure they go, but no more detail, e.g. files etc.

\\server\share\directory1
\\server\share\directory1\subdir1
\\server\share\directory1\subdir2
\\server\share\directory2
\\server\share\directory2\subdir1
\\server\share\directory2\subdir2
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
Assuming PS 3.0 or later, you can just use Get-ChildItem's -Directory argument:
Get-ChildItem -Path \\Server\share -Recurse -Directory | Select-Object -Property FullName, Name | Export-Csv -NoTypeInformation -Path C:\temp\dir.csv

Open in new window

In PS 2.0 or later, you you'll have to filter in PS for PSIsContainer, which takes longer:
Get-ChildItem -Path \\Server\share -Recurse | Where-Object {$_.PSIsContainer} | Select-Object -Property FullName, Name | Export-Csv -NoTypeInformation -Path C:\temp\dir.csv

Open in new window

AlexSenior Infrastructure Analyst

Commented:
$Directory = "./"
Get-ChildItem $Directory -Recurse | % {
    if ($_.Attributes -eq "Directory") {
        Write-Host $_.FullName
    }
}

Open in new window

THat works too, you could even wrap it in a function, let me know if you want that and then you can add it to your powershell folder to have it all the time, I could probably code it so you can use something like get-directory "Share or location"
Top Expert 2014
Commented:
You can add the -Depth parameter to limit the depth of your input tree.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial