首页 > 解决方案 > PowerShell gci -Path C:\ -exclude "Windows" -Directory 不显示目录

问题描述

这些是我的根目录:

gci -路径 C:\ -目录

Mode                LastWriteTime     Length Name                                                                                                  
----                -------------     ------ ----                                                                                                  
d----          1/9/2020  10:35 AM            DevResources                                                                                          
d----         9/12/2018   7:13 AM            inetpub                                                                                               
d----         8/22/2013  10:52 AM            PerfLogs                                                                                              
d-r--        12/11/2019   9:30 AM            Program Files                                                                                         
d----         10/7/2019   2:50 PM            Program Files (x86)                                                                                   
d----         10/3/2018   7:11 AM            Projects                                                                                              
d----         8/22/2019   1:08 PM            SymCache                                                                                              
d----         1/20/2020  10:57 AM            temp                                                                                                  
d-r--        12/11/2019   8:58 AM            Users                                                                                                 
d----         8/22/2019   2:22 PM            Windows                                                                                               
d----         7/31/2019  10:43 PM            Zabbix   

但是当我运行时:

gci -Path C:\ -排除“Windows”-目录

我根本没有得到任何结果。这似乎很容易,但我看不出有什么问题。

我正在使用这个结果来管道到另一个命令来查找最大的文件。

标签: powershell-4.0

解决方案


你是对的。这似乎是一个错误。它在子目录中工作。

gci -path c:\windows -directory -exclude winsxs

它在 6.2.3 的 osx 中给出了一条奇怪的消息:

gci -path / -directory -exclude var

gci : Cannot process argument because the value of argument "path" is not valid. Change the value of the "path" argument and run the operation again.
At line:1 char:1
+ gci -path / -directory -exclude var
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [Get-ChildItem], PSArgumentException
+ FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.GetChildItemCommand

或者在 Windows ps 5.1 - 7 中这样:

dir Microsoft.PowerShell.Core\FileSystem::C:\ -exclude windows

dir : Cannot process argument because the value of argument "path" is not valid. Change the value of the "path" argument and run the operation again.
At line:1 char:2
+  dir Microsoft.PowerShell.Core\FileSystem::C:\ -exclude windows
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-ChildItem], PSArgumentException
    + FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.GetChildItemCommand

这是一种解决方法,但仅适用于 powershell 6 和 7:

get-item c:\ | get-childitem -exclude windows

推荐阅读