Powershell Compare-Object未按预期工作

时间:2011-09-16 13:13:56

标签: powershell compareto

我正在运行以下脚本来将变量中的数据与文本文件中的数据进行比较。结果显示变量中的非数据与文本文件相同,虽然我将它们格式化为相同但结果看起来相同?它们看起来完全相同,为什么powershell认为它们不同?

脚本:

$rn = Get-WMIObject Win32_Process -computer servername -credential domain\administrator -filter "Name='process.exe'” | Select-Object path | Sort-Object path
$lst = Get-Content “C:\Scripts\Process Monitor Scripts\ProcessList.txt”
Compare-Object $lst $rn

Results:
InputObject                             SideIndicator
-----------                             -------------
@{Path=Y:\Folder1\process.exe}        =>
@{Path=Y:\Folder2\process.exe}        =>
@{Path=Y:\Folder3\process.exe}        =>
@{Path=Y:\Folder1\process.exe}        <=
@{Path=Y:\Folder2\process.exe}        <=
@{Path=Y:\Folder3\process.exe}        <=

1 个答案:

答案 0 :(得分:2)

展开path属性,您将对象与路径属性进行比较,而不是简单的字符串。:

$rn = Get-WMIObject Win32_Process -computer servername -credential domain\administrator -filter "Name='process.exe'” | select -expand path