I am trying to print the key value pair from Data Object type XML using a Powershell script.
<?xml version="1.0"?>
<Objects>
<Object Type="System.Management.Automation.PSCustomObject">
<Property Name="Display" Type="System.String">Microsoft</Property>
<Property Name="Service" Type="Microsoft.Management.Service">Database</Property>
</Object>
<Object Type="System.Management.Automation.PSCustomObject">
<Property Name="Display" Type="System.String">Microsoft</Property>
<Property Name="Service" Type="Microsoft.Management.Service">RPC</Property>
</Object>
</Objects>
Here is the script used.
[xml]$file = Get-Content C:\xml-report.xml
foreach ($obj in $file.Objects.Object) {
echo $obj.Display;
echo $obj.Service;
}
How should I iterate through each key (Display, Service) and print only the values of those- i.e
Microsoft
Database
Microsoft
RPC
The output which I get now is as below. Could someone help me here?
Object
Object
Object
$File.SelectNodes('/Objects/Object/Property')|%{$_.'#text'}