我有遍历文件的foreach循环,获取路径并在命令中替换它以获取哈希:
$hash = @{}
...
defining variables here
...
foreach($line in $lines)
{
Get-FileHash $line -Algorithm md5 | format-list | Where { $_ } | Out-File -Width 200 'hash.txt' -Encoding ascii -Append
Get-FileHash $line -Algorithm sha256 | format-list | Where { $_ } | Out-File -Width 200 'hash.txt' -Encoding ascii -Append
Get-FileHash $line -Algorithm sha512 | format-list | Where { $_ } | Out-File -Width 200 'hash.txt' -Encoding ascii -Append
@('MD5','SHA256','SHA512') | % { Get-FileHash -Algorithm $_ $line } | export-csv hash.csv -Delimiter "," -Append
}
我面临的问题是文件开头有 2 个空行,文件末尾有 4 个空行,这是输出:
Algorithm : MD5
Hash : xxx
Path : xxx
Algorithm : SHA256
Hash : xxx
Path : xxx
Algorithm : SHA512
Hash : xxx
Path : xxx
我应该如何摆脱文件开头和结尾的空行?