Powershell 在 -Exclude 中删除具有精确扩展名的文件

Powershell eliminate files with exact extension in -Exclude

我在我的 PowerShell 脚本中使用了这个 cmdlet 来获取路径中除 rdl 文件之外的所有文件:

Get-childitem $path -recurse -Exclude *.rdl | select -expand fullname

问题是该命令还会删除扩展名为“.rdl.rss”的文件,这不是我想要的。

如何只删除扩展名为“.rdl”的文件?谢谢大家

使用Where-Object而不是-Exclude:

Get-ChildItem $path -Recurse |Where-Object {$_.Extension -ne '.rdl'} |Select-Object -ExpandProperty FullName