Powershell比较对象故障

时间:2013-07-16 16:30:58

标签: powershell

这就是我的意思,但不正确。

(Get-Content C:\Users\U0146121\Desktop\Output.txt) |
ForEach-Object {
Compare-Object -referenceobject $_ -DifferenceObject $(get-content C:\Users\U0146121\Desktop\New folder\filenames.txt) -IncludeEqual
}

我想比较当前行,看看它是否在filenames.txt中 如果是,则将名称写入新的txt文件。

2 个答案:

答案 0 :(得分:4)

您不需要循环。

Compare-Object -ReferenceObject (Get-Content .\Two.txt) -DifferenceObject (Get-Content .\One.txt) -IncludeEq
ual | Where {$_.SideIndicator -eq '=='}  | Select -ExpandProperty InputObject | Out-file C:\same.txt

答案 1 :(得分:1)

这与Comparing two arrays & get the values which are not common

类似

将每个文件的内容放入集合$Ref = (Get-Content $origFile); $New = (Get-Content $NewFile);中。确保两个列表包含相同级别的路径引用(绝对路径与相同深度的相对路径)。然后比较两个集合对象。

相关问题