List all subfolders, but only one level deep in a directory.

I’m just putting this here because I was so satisfied that I could do this with one line in Powershell instead of a whole lot more in DOS or VBScript.

List all subfolders in a folder with a depth of one (all folders only in the first level of a directly) to a file and sort everything nicely. You need Powershell v5 or you’ll get an error from some of the parameters.

Get-ChildItem -Directory -Path "C:\temp" -Recurse -Depth 1 -name | Sort-Object |fl | Out-File -FilePath "c:\temp\test.txt"