我正在尝试将System.IO.FileInfo对象(来自不同的Get调用)组合在一起。我从这个问题中找到了工作解决方案(即使用PowerShell数组):Combine the results of two distinct Get-ChildItem calls into single variable to do the same processing on them
$target = "C:\example"
$Files = @( Get-ChildItem -LiteralPath $target -Force -Attributes !D )
$Files += @( Get-ChildItem -LiteralPath $target -Force -Attributes !D ) # for demo. & simplicity, I'm using the same path here
$Files | Write-Host # here the same entries are duplicated但是,来自System.IO.FileInfo对象的相同条目在结果对象中重复。我想知道是否有一种优雅的方法在删除副本的同时组合这些对象?
PS:如果文件具有相同的".FullName“,文件就会被”复制“。
发布于 2022-10-11 07:26:18
$Files = @($Files | Sort-Object -Property FullName -Unique)https://stackoverflow.com/questions/74024225
复制相似问题