将XML与Powershell中的实时数据变量进行比较

将XML与Powershell中的实时数据变量进行比较,xml,powershell,Xml,Powershell,我想将存储在XML文件中的数据与我刚才在这个命令会话中保存到变量中的数据进行比较。有可能吗 我读了这篇文章: 比较对象是比较结果集的好方法。您只需小心确保: 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 specif

我想将存储在XML文件中的数据与我刚才在这个命令会话中保存到变量中的数据进行比较。有可能吗

我读了这篇文章:

比较对象是比较结果集的好方法。您只需小心确保:

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>

可以对它们进行比较,但不能使用compare对象进行比较。您需要编写自己的代码来比较所关心的属性值。或者,您可以将实时数据导出到临时xml文件,然后重新导入该文件,并在该文件上使用compare对象。那么您就不会比较不同的对象类型。

您可以提供一个示例,说明您的XML文件中有哪些内容以及您有哪些变量。当然有可能,问题是如何以最有效的方式实现