【问题标题】:gather information from two different nodes从两个不同的节点收集信息
【发布时间】:2014-10-28 15:01:40
【问题描述】:

我有 xml 数据(在代码下方),我正在尝试将所需的数据导出到 csv 文件。它适用于同一节点下的值,但我需要来自 bios 节点的另一条信息,称为 SerialNumber。我不知道如何同时使用 2 个节点。

[xml] $xdoc = 获取内容 c:\Temp\sinfo.xml

$xdoc.sinfo.systeminfo.sys | Select-Object - 属性模型、制造商、标题、域 |导出-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>

【问题讨论】:

  • 您发布的 xml 无效,所以我无法测试。请更新它
  • @Paul,请立即尝试。
  • 到目前为止您尝试了哪些方法,以及在哪些方面不起作用(显示您的代码)?
  • 现在您的 powershell 代码丢失了^^ 我添加了一个可以让您解决问题的答案

标签: powershell


【解决方案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

【讨论】:

  • 我有这个,工作表显示标题但没有数据。 [xml] $xdoc = Get-Content c:\Temp\sinfo.xml $properties = @{ Serialnumber = $xdoc.systeminfo.bios.SerialNumber; Model = $xdoc.systeminfo.sys.Model; Manufacturer = $xdoc.systeminfo.sys.Manufacturer ComputerName = $xdoc.systeminfo.sys.caption Domain = $xdoc.systeminfo.sys.domain } $obj = new-object psobject -property $properties | Export-Csv c:\Temp\results.csv -Force -NoTypeInformation
  • @Kent 是的,我在拥有正确的 xml 之前就这样做了,我更新了它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-08-10
  • 1970-01-01
  • 2023-03-28
  • 2023-02-21
  • 1970-01-01
  • 2021-12-21
  • 1970-01-01
相关资源
最近更新 更多