powershell folder structure command - csv output

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
LVL 4
pma111Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Alex GreenProject Systems EngineerCommented:
$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"
aikimarkCommented:
You can add the -Depth parameter to limit the depth of your input tree.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.