Powershell read xml value



I have the following XML & I'm trying to obtain the value corresponding to Name=ComponentVersion.



<Component .......>
<Settings>
<Setting Name="ComponentVersion" Value="12345" />
<Setting Name="Host" Value="false" />
</Settings>
<Jobs>
<Job Name="Platform" />
</Jobs>
</Component>


Here's what i have tried..



$fullPathXML = "$env:PackagesPath\Platform\Components\SystemPlatform.Comp.xml"


[xml]$xmlSystemPlatform = Get-Content $fullPathXML




  1. $xmlSystemPlatform.selectNodes('//Settings/Setting') | select Name




  2. Select-Xml '//Settings/Setting[contains(@Name, "ComponentVersion")]' $xmlSystemPlatform |%{$_.Node.Value}




  3. $xmlSystemPlatform.Settings.Setting[0].Name


    $xmlSystemPlatform.Settings.Setting[0].Value





How do I get the value for Name corresponding to ComponentVersion?


No comments:

Post a Comment