我如何为我的 powershell 命令使用过滤器?

How can i use filter for my powershell command?

我的 powershell 命令搜索文件夹中的文件并对它们的字节进行编码。

get-childitem -path "S:\db\test"  -depth 1 | Select-Object FullName, @{Name="Hash";Expression={Get-Content $_.FullName -Encoding Byte | select -first 5}} 

输出是文件的全名和字节的前 5 位数字。

FullName                     Hash            
--------                     ----            
S:\db\test                 {1, 15, 0, 0, 0}
S:\db\test.bmp             {1, 15, 0, 0, 8}

我想对字节值使用过滤器。例如;仅适用于 1,15,0,0,0 字节值的文件名。

我无法使用 where-object 或 -filter。

谢谢。

使用数组进行比较并不是 PowerShell 的强项(特别是因为与数组作为左操作数的比较具有不同的语义)。在这种情况下使用字符串通常更容易:

... | where { '' + $_.Hash -eq '1 15 0 0 0' }