从 powershell Get-ChildItem 结果中排除文件

Exclude file from powershell Get-ChildItem results

为了 select 每个目录中的每个 AssemblyInfo.cs 减去一个,我 运行 一个 powershell 脚本 :

Clear-Host
$SrcDir = "D:\Projects\Lambda\Sources"
Write-Host $SrcDir
cd $SrcDir
$ExcludeXYZCallStrategy = $SrcDir + "\Lambda.XYZ\XYZCallStrategy\Properties\AssemblyInfo.cs"
# 2. Select Files to be updated
Write-Host $ExcludeXYZCallStrategy
# both these syntaxes fail (tried one after the other not together ofc) :
$Assemblyfiles = Get-ChildItem -Path $SrcDir -Recurse -Include AssemblyInfo.cs -Exclude $ExcludeXYZCallStrategy
$Assemblyfiles = Get-ChildItem -Path $SrcDir -Recurse -Include AssemblyInfo.cs -Exclude D:\Projects\Lambda\Sources\Lambda.XYZ\XYZCallStrategy\Properties\AssemblyInfo.cs
Write-Host $Assemblyfiles
Write-Host "Files Count : " $Assemblyfiles.count

我尝试了不同的语法来强制 Get-ChildItem 排除那个文件,但我失败了。

我尝试了这些答案但无济于事:

doc 中,我找不到任何可以解释为什么不排除该文件的内容。

因为只有一个文件,您可以使用 Where-Object.

$Assemblyfiles = Get-ChildItem -Path $SrcDir -Recurse -Include AssemblyInfo.cs | Where-Object { $_.FullName -ne "D:\Projects\Lambda\Sources\Lambda.XYZ\XYZCallStrategy\Properties\AssemblyInfo.cs" }