我有xml数据(在代码下面),我正在尝试将所需数据导出到csv文件。它适用于同一节点下的值,但我还需要来自bios节点的一个名为SerialNumber的信息。我无法弄清楚如何同时使用2个节点。
[xml] $ xdoc = Get-Content c:\ Temp \ sinfo.xml
$ xdoc.sinfo.systeminfo.sys | Select-Object -Property模型,制造商,标题,域名| export-csv c:\ temp \ results.csv -NoTypeInformation
<?xml version="1.0" ?>
<sinfo hostname="server" tstamp="1414467481" wintime="130589410811659818" ctime="Mon Oct 27 23:38:01 2014" ver="1.1.4" platform="Windows" machine="Win32NT">
<systemInfo>
<bios>
<BIOSVersion>HP - 2</BIOSVersion>
<Caption>Default System BIOS</Caption>
<Description>Default System BIOS</Description>
<Manufacturer>HP</Manufacturer>
<Name>Default System BIOS</Name>
<PrimaryBIOS>True</PrimaryBIOS>
<ReleaseDate tstamp="1380600000" utc="130250736000000000" >10-01-2013 00:00:00</ReleaseDate>
<SerialNumber>MXQ046045fdgfJ</SerialNumber>
<SMBIOSBIOSVersion>P65</SMBIOSBIOSVersion>
<SMBIOSMajorVersion>2</SMBIOSMajorVersion>
<SMBIOSMinorVersion>7</SMBIOSMinorVersion>
<SMBIOSPresent>True</SMBIOSPresent>
<SoftwareElementID>Default System BIOS</SoftwareElementID>
<SoftwareElementState>3</SoftwareElementState>
<Status>OK</Status>
<TargetOperatingSystem>0</TargetOperatingSystem>
<Version>HP - 2</Version>
</bios>
<boot>
<BootDirectory>C:\Windows</BootDirectory>
<ConfigurationPath>C:\Windows</ConfigurationPath>
<LastDrive>Y:</LastDrive>
<Name>BootConfiguration</Name>
<ScratchDirectory>C:\Windows\system32\config\systemprofile\AppData\Local\Temp</ScratchDirectory>
<TempDirectory>C:\Windows\system32\config\systemprofile\AppData\Local\Temp</TempDirectory>
</boot>
<enclosure>
<Caption>System Enclosure</Caption>
<Description>System Enclosure</Description>
<LockPresent>False</LockPresent>
<Manufacturer>HP</Manufacturer>
<Name>System Enclosure</Name>
<SecurityStatus>2</SecurityStatus>
<SerialNumber>MXedterQ046J</SerialNumber>
<SMBIOSAssetTag></SMBIOSAssetTag>
<Tag>System Enclosure 0</Tag>
</enclosure>
<sys>
<AdminPasswordStatus>3</AdminPasswordStatus>
<AutomaticManagedPagefile>True</AutomaticManagedPagefile>
<AutomaticResetBootOption>True</AutomaticResetBootOption>
<AutomaticResetCapability>True</AutomaticResetCapability>
<BootROMSupported>True</BootROMSupported>
<BootupState>Normal boot</BootupState>
<Caption>STRATUS</Caption>
<ChassisBootupState>3</ChassisBootupState>
<CurrentTimeZone>-240</CurrentTimeZone>
<DaylightInEffect>True</DaylightInEffect>
<Description>AT/AT COMPATIBLE</Description>
<DNSHostName>server</DNSHostName>
<Domain>ten.domain.com</Domain>
<DomainRole>3</DomainRole>
<EnableDaylightSavingsTime>True</EnableDaylightSavingsTime>
<FrontPanelResetStatus>3</FrontPanelResetStatus>
<InfraredSupported>False</InfraredSupported>
<KeyboardPasswordStatus>3</KeyboardPasswordStatus>
<Manufacturer>HP</Manufacturer>
<Model>ProLiant DL580 G7</Model>
<Name>server</Name>
<NetworkServerModeEnabled>True</NetworkServerModeEnabled>
<NumberOfLogicalProcessors>16</NumberOfLogicalProcessors>
<NumberOfProcessors>2</NumberOfProcessors>
<OEMStringArray>PSF:</OEMStringArray>
<OEMStringArray>Product ID: 595241-001</OEMStringArray>
<PartOfDomain>True</PartOfDomain>
<PauseAfterReset>-1</PauseAfterReset>
<PCSystemType>0</PCSystemType>
<PowerOnPasswordStatus>3</PowerOnPasswordStatus>
<PowerState>0</PowerState>
<PowerSupplyState>3</PowerSupplyState>
<PrimaryOwnerName>dfsdfsdf</PrimaryOwnerName>
<ResetCapability>1</ResetCapability>
<ResetCount>-1</ResetCount>
<ResetLimit>-1</ResetLimit>
<Roles>LM_Workstation</Roles>
<Roles>LM_Server</Roles>
<Roles>SQLServer</Roles>
<Roles>NT</Roles>
<Roles>Server_NT</Roles>
<Roles>DFS</Roles>
<Status>OK</Status>
<SystemType>x64-based PC</SystemType>
<ThermalState>3</ThermalState>
<TotalPhysicalMemory>34359738368</TotalPhysicalMemory>
<WakeUpType>6</WakeUpType>
</sys>
</systemInfo>
</sinfo>
答案 0 :(得分:1)
试试这个:
$properties = @ {
Serialnumber=$xdoc.sinfo.systeminfo.bios.SerialNumber;
Model=$xdoc.sinfo.systeminfo.sys.Model;
Manufacturer=$xdoc.sinfo.systemionfo.sys.Manufacturer;
Caption=$xdoc.sinfo.systeminfo.sys.Caption;
Domain=$xdoc.sinfo.systeminfo.sys.Domain
}
$obj = new-object psobject -property $properties
这将提供一个对象,该对象将包含您在$ properties哈希表中选择的所有属性
然后你可以做
$obj | Select-Object model, manufacturer, caption, domain, SerialNumber | export-csv c:\temp\results.csv -NoTypeInformation