Powerhsell Get-ChildItem folders only

02 May,2017 by Jack Vamvas

Question: When I’m using Powershell Get-ChildItem I get a recordset to get all files in directory. It also returns all the folders in the currrent directory. I’d like to be able to return only folders and exclude all  files.

How can I return folders only using Get-ChildItem?

Answer: Since Powershell 3.0 , it’s straightforward to return Get-ChildItem folders only. The following is an example@

                   Get-ChildItem –Directory

You can also use

                    Dir –Directory    

Dir is an alias for Get-ChildItem

 

If you’re still using Powershell versions earlier tham v3.0 then you’ll need to use a different tactic.

                   Get-ChildItem -Recurse | ?{ $_.PSIsContainer } | Select-Object FullName

 

 

If you're interested in exploring Powershell Get-ChildItem read these posts

Powershell get-childitem and date modified (SQL Server DBA)

SQL Server - Powershell Get-ChildItem with examples (SQL Server ...

 

There are hundreds of free  Powershell Scripts which you can use for your DBA work

 


Author: Jack Vamvas (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on Powerhsell Get-ChildItem folders only


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer