02 May,2017 by Tom Collins
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
This is only a preview. Your comment has not yet been posted.
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.
Posted by: |