powershell - 使用 Get-ChildItem -Exclude 或 -Include 不返回任何内容

标签 powershell powershell-4.0

我的 C: 目录中有一个包含许多文件的列表。如果我尝试对其运行 -Exclude ,则不会得到任何返回。与 -Include 相同。如果我使用过滤器,它会返回我期望返回的内容。我不明白它应该做什么吗?

这是我正在运行但一无所获的示例:

Get-ChildItem -Path C: -Exclude "*.txt"

我什么也得不到。如果我跑
Get-Childitem -filter "*.txt"

我得到这个:
  Mode                LastWriteTime         Length Name                                                                               
----                -------------         ------ ----                                                                               
-a----        11/7/2007   8:00 AM          17734 eula.1028.txt                                                                      
-a----        11/7/2007   8:00 AM          17734 eula.1031.txt                                                                      
-a----        11/7/2007   8:00 AM          10134 eula.1033.txt                                                                      
-a----        11/7/2007   8:00 AM          17734 eula.1036.txt                                                                      
-a----        11/7/2007   8:00 AM          17734 eula.1040.txt                                                                      
-a----        11/7/2007   8:00 AM            118 eula.1041.txt                                                                      
-a----        11/7/2007   8:00 AM          17734 eula.1042.txt                                                                      
-a----        11/7/2007   8:00 AM          17734 eula.2052.txt                                                                      
-a----        11/7/2007   8:00 AM          17734 eula.3082.txt                                                                      
               7/7/2016   8:50 AM             93 HaxLogs.txt                                                                        
-a----         7/8/2016   8:30 AM              0 Test.txt 

最佳答案

Get-ChildItem -Path "C:\*" -Include "*.txt"

这个例子,如何-Include应该工作,会给你你期望的结果。请注意,我还在路径参数中提供了一个通配符,以将路径明确定义为“根 C: 中的任何文件”,而不是“C:”本身。

来源:
https://technet.microsoft.com/library/hh849800.aspx

此链接中的示例 3,以防它失效(请注意此处路径中的通配符):
C:\> Get-ChildItem –Path "C:\Windows\Logs\*" -Include "*.txt" -Exclude "A*"

关于powershell - 使用 Get-ChildItem -Exclude 或 -Include 不返回任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38269209/

相关文章:

powershell - PowerShell字符串默认参数值未按预期运行

windows - 将多个输出组合成一个表

c# - Powershell 加载自定义程序集配置文件

powershell - 恶意软件使用 .Lnk 文件到 Powershell

excel - 如何使用powershell将excel 2007保存为html格式?

Powershell 命令在 Visual Studio 的构建事件中不起作用

mysql - 如何循环遍历两个列表以查看变量是否相同?

powershell - Powershell附加CSV错误

Powershell: "Help Get-Content -Full"缺少一些参数(原始、流、编码)

powershell - 使用 powershell 删除 azure 存储帐户