如何在 PowerShell 中的 Get-ChildItem 中仅获取文件夹而不获取文件?

powershellmicrosoft technologiessoftware & coding

要仅获取文件夹而不获取文件,我们需要使用带有 Directory 属性的 –Attribute 参数。

命令

Get-ChildItem D:\Temp\ -Attributes Directory

输出

Directory: D:\Temp
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       13-12-2019     09:52                GPO_backup
d-----       24-11-2018     11:31                LGPO

同样,您可以组合不同的操作。

要获取唯一的系统目录,请使用以下命令。

Get-ChildItem D:\Temp\ -Attributes Directory -Recurse –System -Recurse

获取隐藏的系统目录。

Get-ChildItem D:\Temp\ -Attributes Directory -Recurse –System -Hidden

获取只读的系统目录。

Get-ChildItem D:\Temp\ -Attributes Directory -Recurse –System -Readonly

相关文章