前两个答案都非常优秀,非常感谢。希望我可以将它们标记为答案。回答我自己的问题,以便我可以删除一些代码,我认为我不能在评论中做。
我的解决方案(耶,吃午饭和他的动手):
ls VisitRecord-1/Release,Dispo-1/Release -rec `
| % {@{FileName=$_.Name; ProductName=$_.VersionInfo.ProductName; ProductVersion=$_.VersionInfo.ProductVersion }} `
| New-HashObject `
| group FileName,ProductName,ProductVersion `
| % {$grp = $_.Name -split ', '; @{Count=$_.Count; FileName=$grp[0]; ProductName=$grp[1]; ProductVersion=$grp[2]}} `
| New-HashObject `
| Select Count,FileName,ProductName,ProductVersion `
| sort ProductName,FileName `
| ft -auto
不过似乎有点矫枉过正,但我就认为这是错误的解决方法。
我喜欢PSCX,但是我对当地PS和什么是PSCX感到困惑。我认为New-HashObject 的胜利可能是,因为它可以在其输入上生成一串哈希表并产生一个对象流。可能的性能增益?
无论如何,高兴地发现它是PS 2.0中的一个错误。我想这是一个足够好的理由来升级。 :)安装PS 3.0
重写命令行后
编辑:
ls VisitRecord-1/Release,Dispo-1/Release -rec `
| % {@{FileName=$_.Name; `
ProductName=$_.VersionInfo.ProductName; `
ProductVersion=$_.VersionInfo.ProductVersion }} `
| New-HashObject `
| group FileName,ProductName,ProductVersion `
| % {@{Count=$_.Count; `
GroupCount=$_.Group.Count; `
FileName=$_.Group[0].FileName; `
ProductName=$_.Group[0].ProductName; `
ProductVersion=$_.Group[0].ProductVersion}} `
| New-HashObject `
| select Count,GroupCount,FileName,ProductName,ProductVersion `
| sort ProductName,FileName `
| ft -auto
加送GroupCount为了说明,添加了[0]到组的引用。也许这会让它在PS 2.0下工作,但现在还没有回头(对我来说)。 :)
(编辑:而这一切之后,上述不工作PS 2.0下,毕竟)
更多比你想要了解集团的对象:
ls VisitRecord-1/Release,Dispo-1/Release -rec `
| % {@{FileName=$_.Name; ProductName=$_.VersionInfo.ProductName; ProductVersion=$_.VersionInfo.ProductVersion }} `
| New-HashObject `
| group FileName,ProductName,ProductVersion `
| ? {($_.Count -gt 1) -and ($_.Group[0].ProductName -ne $Null)} `
| select -first 1 `
| fl
Name : Infragistics4.Shared.v13.1.dll, Infragistics4.Shared, 13.1.20131.2060
Count : 2
Group : {@{ProductVersion=13.1.20131.2060; FileName=Infragistics4.Shared.v13.1.dll; ProductName=Infragistics4.Shared},
@{ProductVersion=13.1.20131.2060; FileName=Infragistics4.Shared.v13.1.dll; ProductName=Infragistics4.Shared}}
Values : {Infragistics4.Shared.v13.1.dll, Infragistics4.Shared, 13.1.20131.2060}
看起来不需要周围的$()。在看到Keith Hill的回答后,我尝试了没有它的版本,并且这也起作用。 –
这不是一个错误。 PowerShell V3添加了成员枚举,这就是$ Collection.Property($ _。Group.Filename)在V3和更高版本中工作的原因。 –
@凯特希尔啊,我明白你在说什么了。我忽略了他没有尝试读取** GroupInfo **对象本身的属性,因为** $ _ **是** GroupInfo **对象,并且** $ _。Group **是该属性的一个属性** GroupInfo **对象,它是一个集合。所以他的代码在PS 2.0中不起作用,因为他试图读取集合的成员属性,并且它仅在3.0中工作,因为集合恰好在每种情况下都只有一个对象。在那种情况下,我有一个更好的答案 - 只需在'.Group'后添加'[0]',这是唯一需要的修改。我会更新我的答案。 –