How to get value from xml from PowerShell?

I have an XML file with this data

<?xml version="1.0" encoding="windows-1251" ?> <ValCurs Date="06/06/2012" name=" "> <Valute ID="036"> <CharCode>AUD</CharCode> <Nominal>1</Nominal> <Name> </Name> <Value>4,6430</Value> </Valute> <Valute ID="944"> <CharCode>AZN</CharCode> <Nominal>1</Nominal> <Name> &#1207;</Name> <Value>6,0677</Value> </Valute> <Valute ID="826"> <CharCode>GBP</CharCode> <Nominal>1</Nominal> <Name>- </Name> <Value>7,3156</Value> </Valute> ... 

other

How can I get data in "Nominal" and "Value" using the criteria "Valute ID =" 826 "? Sorry for my English

+6
source share
1 answer

You can read the XML simply by hovering the line in [xml] :

 $xml = [xml](Get-Content foo.xml) 

Then you can use

 $xml.ValCurs.Valute | Where-Object {$_.ID -eq 826} | Select-Object Nominal,Value 

or shorter:

 $xml.ValCurs.Valute | ? {$_.ID -eq 826} | select Nominal,Value 
+20
source

Source: https://habr.com/ru/post/919751/


All Articles