Monday, January 9, 2012

Retrieve Exchange Rates using PowerShell

 

PowerTip of the Day, from PowerShell.com:

If you need up-to-date exchange rates, try loading the rates via XML from the European Central Bank. This sample gets you the latest exchange rates for USD-EUR conversion. It also has a link to other currency data. Just exchange the data link. We included a sample for Danish currency as well.

#Exchangerate feeds : http://www.ecb.int/home/html/rss.en.html

$url = 'http://www.ecb.int/rss/fxref-usd.html'

#$url = 'http://www.ecb.int/rss/fxref-dkk.html'

$xml = New-Object xml

$xml.Load($url)

$xml.RDF.Item |

      ForEach-Object {

            $rv = 1 | Select-Object Date, Currency, Rate, Description

            $rv.Date = [DateTime]$_.Date

            $rv.Description = $_.description.'#text'

            $rv.Currency = $_.statistics.exchangeRate.targetCurrency

            $rv.rate = $_.statistics.exchangeRate.value.'#text'

            $rv

      }

And this is what the output looks like (provided you have Internet access and no proxy is required):

Date                                          Currency Rate       Description

----                                          -------- ----       -----------

01.12.2011 14:15:00 USD               1.3492 1 EUR buys 1.3492 US dollar (USD) - The
...

30.11.2011 14:15:00 USD               1.3418 1 EUR buys 1.3418 US dollar (USD) - The
...

29.11.2011 14:15:00 USD               1.3336 1 EUR buys 1.3336 US dollar (USD) - The
...

28.11.2011 14:15:00 USD               1.3348 1 EUR buys 1.3348 US dollar (USD) - The
...

25.11.2011 14:15:00 USD               1.3229 1 EUR buys 1.3229 US dollar (USD) - The
...

 

Thanks

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.