Current EUR/USD exchange rate with three lines in Powershell
Posted: (EET/GMT+2)
The European Central Bank (ECB) hosts a nice XML file with the latest exchange rates. To get the latest EUR/USD exchange rate, use these three simple lines in PowerShell:
$url = "http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"
[xml]$rates = (New-Object System.Net.WebClient).DownloadString($url)
$rates.Envelope.Cube.Cube.Cube | ? {$_.currency -eq "USD"}
Very easy thanks to the System.Net.WebClient class and its DownloadString method. But I must say I'm more and more impressed with PowerShell, there's also XML element completion with the Tab key. :-) PowerShell rocks!