Powershell 比较对象未按预期工作
我正在运行以下脚本来将变量中的数据与文本文件中的数据进行比较。结果显示变量中的数据没有与文本文件相同,尽管我将它们格式化为相同并且它们在结果中看起来相同?它们看起来相同,为什么 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} <=
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} <=
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
展开路径属性,您将具有路径属性的对象与简单字符串进行比较:
Expand the path property, you're comparing objects with a path property against simple strings.: