我正在寻找共享驱动器上的重复项,因此我可以让用户知道,他们可以在我们使用任何自动化方法之前对其进行清理。我最大的副本将近400份,但信息全部在一行上。
我的查询得到正确的结果:
$a = Get-ChildItem -Path "S:\" -File -Recurse |
Select-Object -Property Fullname, @{N='Hash';E={(Get-FileHash $_.FullName).Hash}}
$cnt = $a | Group-Object -Property Hash
$cnt |
Select-Object Count, @{N='FullName';E={($_.Group).FullName}}, @{N='Hash';E={($_.Group).Hash}} |
Sort-Object -Property Count -Descending |
Export-Csv C:\Temp\S_Drive_Counts.csv
这是我的结果的示例,其中每个条目都在一行上:
"Count","FullName","Hash" "2","S:\Generation 1\Certification Authority.txt S:\Generation 2\Certification Authority.txt","498868376A5377F731593E9F96EC99F34C69F47537C81B9B32DBAC9321462B83 498868376A5377F731593E9F96EC99F34C69F47537C81B9B32DBAC9321462B83"
尽管我需要传递此信息,所以我想将每个条目单独放在一行上,类似于:
"Count","FullName","Hash" "2","S:\Generation 1\Certification Authority.txt","498868376A5377F731593E9F96EC99F34C69F47537C81B9B32DBAC9321462B83" "2","S:\Generation 2\Certification Authority.txt","498868376A5377F731593E9F96EC99F34C69F47537C81B9B32DBAC9321462B83"
如果需要,我可以对CSV进行一些字符串操作,但是我正在寻找一种在导出到CSV之前以正确格式获取它的方法。
答案 0 :(得分:1)
展开您的组。另外,更好地利用管道。
Get-ChildItem -Path 'S:\' -File -Recurse |
Select-Object Fullname, @{n='Hash';e={(Get-FileHash $_.FullName).Hash}} |
Group-Object Hash |
ForEach-Object {
$cnt = $_.Count
$_.Group | Select-Object @{n='Count';e={$cnt}}, FullName, Hash
} |
Sort-Object Count, Hash, FullName -Descending |
Export-Csv 'C:\Temp\S_Drive_Counts.csv' -NoType