我想将存储在XML文件中的数据与我刚刚保存到此命令会话中的变量的数据进行比较。它甚至可能吗?
我读过这篇文章:http://powershell.com/cs/blogs/tobias/archive/2009/01/09/tipps-amp-tricks-using-compare-object.aspx
“Compare-Object是比较结果集的好方法。您只需要小心确保:
you are comparing the same object types (do not mix imported xml data with live data)
the syncWindow is large enough to cover the number of expected differences
you specify the properties you really want to compare
“
请告诉我可以将导入的xml数据与实时数据进行比较:P
这是我的XML:
<computer version="1.0">
<hardware>
<serialnr>78456214Q</serialnr>
<systeminfo>
<name>Macgyver</name>
<domain>Inventory.Domain</domain>
<manufacturer>TOSHIBA</manufacturer>
<model>Satellite A300</model>
<bitversion>x64-based PC</bitversion>
</systeminfo>
<gpu>
<name>ATI Mobility Radeon HD 3400 Series</name>
<status>OK</status>
</gpu>
<cpu>
<name>Intel(R) Core(TM)2 Duo CPU T5750 @ 2.00GHz</name>
<manufacturer>GenuineIntel</manufacturer>
<id>cpuid</id>
<numberofcores>2</numberofcores>
<addresswidth>64</addresswidth>
</cpu>
<usb>
<model>TOSHIBA MK2552GSX ATA Device</model>
</usb>
<drive>
<name>C:</name>
<volumename>Vista</volumename>
<size>116,29 GB</size>
<freespace>25,88 GB</freespace>
</drive>
<drive>
<name>D:</name>
<volumename>Disk</volumename>
<size>115,13 GB</size>
<freespace>114,03 GB</freespace>
</drive>
<memory>
<positioninrow>1</positioninrow>
<size>2 GB</size>
<datawidth>64</datawidth>
<devicelocator>DIMM0</devicelocator>
</memory>
<memory>
<positioninrow>2</positioninrow>
<size>2 GB</size>
<datawidth>64</datawidth>
<devicelocator>DIMM2</devicelocator>
</memory>
</hardware>
<software>
<printer>
<drivername>Microsoft XPS Document Writer</drivername>
</printer>
<printer>
<drivername>Microsoft Shared Fax Driver</drivername>
</printer>
<user>
<name>Administrator</name>
</user>
<user>
<name>Guest</name>
</user>
<user>
<name>Hkon</name>
</user>
<user>
<name>HomeGroupUser$</name>
</user>
<osinfo>
<caption>Microsoft Windows 7 Ultimate </caption>
<serialnumber>03426-OEM-8672362-00056</serialnumber>
<installdate>06/07/2010 15:37:05</installdate>
<OSArchitecture>64-bit</OSArchitecture>
<manufacturer>Microsoft Corporation</manufacturer>
</osinfo>
<network>
<IP>158.38.54.48 fe90::8b3:b35e:e5d4:91f7</IP>
<Name>Intel(R) PRO/Wireless 3945ABG Network Connection</Name>
<MAC>00:1F:3C:8E:32:D9</MAC>
</network>
</software>
</computer>
答案 0 :(得分:0)
可以比较它们,你不能使用compare-object来做到这一点。您需要编写自己的代码来比较您关注的属性值。或者,您可以将实时数据导出到临时xml文件,然后重新导入它并在其上使用compare-object。那么你不是在比较不同的对象类型。