質問

I'm running the following script to compare data within a variable to data within a text file. The results show that non of the data within the variable is the same as the text file, although I've formatted them the same and they look the same in the results? They look identical, why does powershell think they're different?

Script:

$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}        <=
役に立ちましたか?

解決

Expand the path property, you're comparing objects with a path property against simple strings.:

$rn = Get-WMIObject Win32_Process -computer servername -credential domain\administrator -filter "Name='process.exe'” | select -expand path
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top