如何结合 Get-ChildItem 和 Get-FileHash 输出?电源外壳

how to combine Get-ChildItem and Get-FileHash output? powershell

我想获得 table 类似文件的名称算法哈希,在文件夹中以 .gz 结尾

过滤效果很好: powershell -command " Get-ChildItem -Filter 'L04\*.gz' | Select Name" 给一个 table:

Name
v300040828_run20_L04_62_1.fq.gz 
v300040828_run20_L04_62_2.fq.gz

但是带有散列的 upgreid 命令 powershell -command " Get-ChildItem -Filter 'L04\*.gz' | ls | Get-FileHash -Algorithm MD5| Select Name,Algorithm,Hash" 只给我没有名字的alg和hash..

   Name Algorithm Hash
      MD5 08B622CFAB1254DE77DEE2B86B8566C5
      MD5 BB0ACF3AE1F9E67BAF8F64736221D401

请帮我取名字

Get-FileHash returns 具有属性 PathAlgorithmHash.
的对象 路径是文件的全名。

如果你想改变,你可以

Select-Object @{Name = 'Name'; Expression = {[System.IO.Path]::GetFileName($_.Path)}}, Algorithm, Hash
$GCIArgs = @{Path   = "G:\BEKDocs\Scripts\DiskSpaceGUI"
             Filter = '*.ps1'}
Get-ChildItem  @GCIArgs |
  Get-FileHash -Algorithm MD5|
  Select-Object Algorithm,Hash,@{
      n="Name";e={($_.Path).Split("\")[-1]}}

结果:

Algorithm Hash                             Name                   
--------- ----                             ----                   
MD5       FDD38964CA6EC73C01FB5097E8EFFE9E DiskSpaceGUI-V1-0.ps1  
MD5       2991850091CA66634BC9287E00FB086C DiskSpaceGUI-V2-0.1.ps1
MD5       2991850091CA66634BC9287E00FB086C DiskSpaceGUI-V2-0.ps1  
MD5       A9ECA8BF38D57D953E51C11D3F881A4F DiskSpaceGUI-V2-1.ps1  
MD5       E265F9DCCC1BE106C71789F6040DBAEB DiskSpaceGUI-V2-3.ps1  
MD5       FB287373331EB4716FAF0CFC99FF2390 DiskSpaceGUI-V2-4.ps1  
MD5       B370CD26B814B63A5779CB4BD1630E9F DiskSpaceGUI.ps1       

HTH